I've got some strings to split. They are main words, but some words
are inside a pair of brackets and should be considered as one unit. I
prefer to use re.split, but haven't written a working one after hours
of work.
Example:
"a (b c) d [e f g] h i"
should be splitted to
["a", "(b c)", "d", "[e f g]", "h", "i"]
As speed is a factor to consider, it's best if there is a single line
regular expression can handle this. I tried this but failed:
re.split(r"(?![\(\[].*?)\s+(?!.*?[\)\]])", s). It work for "(a b) c"
but not work "a (b c)" :(
Re: splitting words with brackets ...Qiangning Hong wrote: ... are inside a pair of brackets and should be considered as one unit. ...regular expression can handle this. ... Any hint?... (comp.lang.python)
Re: Looking for a regexp generator based on a set of known string representative of a string set ... If all you have are those strings, you are better off trying to infer ... So I would suggest that the OP explain what he intends to do with his regular expression.... Of two contending targets the longer prevails. ... "There was a BEE BELONGing to hive nine LONGing to BE a BEEtle and thinking that BEING a BEE was okay, but she had BEEN a BEE LONG ... (comp.lang.python)
Re: trying to create a multiple pattern matcher ...Tom McGlynn wrote: ... You can certainly use "|)" but AFAIK regexs don't tell you ... intricate than just a simple choice between two literal strings.... or'ed regular expression that had a match, 0 if it matches and is not ... (comp.lang.java.programmer)
Re: trying to create a multiple pattern matcher ...Tom McGlynn wrote: ... You can certainly use "|)" but AFAIK regexs don't tell you ... or'ed regular expression that had a match, 0 if it matches and is not ... Let me reinstate that I was just using a simple case to get my point across even if you actually use a true regexp, you may still need to know which one was the one that matched instead of passing the same strings and reset the matcher as many times as you need to replace some string. ... (comp.lang.java.programmer)
Re: trying to create a multiple pattern matcher ...Tom McGlynn wrote: ... You can certainly use "|)" but AFAIK regexs don't tell you ... or'ed regular expression that had a match, 0 if it matches and is not ... Let me reinstate that I was just using a simple case to get my point across even if you actually use a true regexp, you may still need to know which one was the one that matched instead of passing the same strings and reset the matcher as many times as you need to replace some string. ... (comp.lang.java.programmer)