java - Unlimited quantifiers in a complex lookbehind -
java - Unlimited quantifiers in a complex lookbehind -
i'm having lot of problem writing regular expression:
(?<=\s+|^\s*|\(\s*|\.)(?:item|item1|item2)(?=\s+|\s*$|\s*\)|\.)
it works on regex editor (expresso) , in .net environment, in java environment (jre 1.6.0.25 using eclipse helios r2) doesn't work because pattern.compile()
method throws "syntax error u_regex_look_behind_limit" exception.
that's because behind pattern (?<=\s+|^\s*|\(\s*|\.)
must have defined limit (unlimited quantifiers such *
, +
not allowed here far know).
i tried specify range of repetition in way no luck:
(?<=\s{0,1000}|^\s{0,1000}|\(\s{0,1000}|\.)(?:item|item1|item2)(?=\s+|\s*$|\s*\)|\.)
so, how can write identical regex works on java environment? can't believe there's no workaround kind of mutual situation....
keep in mind lookbehind far behind must. example, (?<=\s+)
satisfied if previous character space; doesn't need farther back.
the same true of lookbehind. if it's not origin of string , previous character not whitespace, open-parenthesis or period, there's no point looking farther back. it's equivalent this:
(?<=^|[\s(.])
your lookahead can condensed in same way. if it's not end of string, , next character not whitespace, close-parenthesis or period, there's no point looking further:
(?=[\s).]|$)
so final regex is:
(?<=^|[\s(.])(?:item|item1|item2)(?=[\s).]|$)
java regex lookbehind
Comments
Post a Comment