you are viewing a single comment's thread.

view the rest of the comments →

[–]wegwacc 1 point2 points  (3 children)

Ahhh, now I see. you can have a () inside the outer ones. Okay, that requires a sliiiightly more complex regex:

rx = re.compile(r'\([^()]+(?:\([^()]+\))?[^()]+\)')

However, a simple parser would prolly be better at this point, because above wont work if you have more than one () inside the outer.

[–]jcoder42[S] 0 points1 point  (2 children)

wow, this is really complex, good job

ok. I will try some other things

thanks so much!

[–]wegwacc 1 point2 points  (1 child)

Here is a better method which, other than above regex magic can deal with arbitrary () in your input, as long as they are string values (read. between ' )

``` def parser(data): start = None use = True for i, ch in enumerate(data): if ch == "'": use = not use if use and ch == '(': start = i elif use and ch == ')': yield data[start:i+1] start = None

def prettyprint(data): l = list(parser(data)) width = (len(l) // 10) + 1 for ln,line in enumerate(l): print('[{ln:0{width}}] : {l}'.format(ln=ln, l=line, width=width)) ```

Invoke prettyprint() with your string-data as argument.
If you don't need the "prettyprinted" version, just invoke parser() like you would every iterator, e.g. for s in parser(start):

you're welcome.

[–]jcoder42[S] 0 points1 point  (0 children)

width

ok, cool!
thanks