Java regex error – Look-behind group does not have an obvious maximum length
To avoid this error, you should replace + with a region like {0,10}: ([a-z])(?!.*\1)(?<!\1.{0,10})([a-z])(?!.*\2)(?<!\2.{0,10})(.)(\3)(.)(\5)
To avoid this error, you should replace + with a region like {0,10}: ([a-z])(?!.*\1)(?<!\1.{0,10})([a-z])(?!.*\2)(?<!\2.{0,10})(.)(\3)(.)(\5)
This sounds like a job for lookbehinds, though you should be aware that not all regex flavors support them. In your example: (?<=\bipsum\s)(\w+) This will match any sequence of letter characters which follows “ipsum” as a whole word followed by a space. It does not match “ipsum” itself, you don’t need to worry about reinserting … Read more
The answer to the question you ask, which is whether a larger class of languages than the regular languages can be recognised with regular expressions augmented by lookaround, is no. A proof is relatively straightforward, but an algorithm to translate a regular expression containing lookarounds into one without is messy. First: note that you can … Read more
From the documentation: (?<!…) Matches if the current position in the string is not preceded by a match for …. This is called a negative lookbehind assertion. Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning … Read more
regex module: variable-width lookbehind In addition to the answer by HamZa, for any regex of any complexity in Python, I recommend using the outstanding regex module by Matthew Barnett. It supports infinite lookbehind—one of the few engines to do so, along with .NET and JGSoft. This allows you to do for instance: import regex if … Read more
Looks like your suspicion is correct that backreferences generally can’t be used in Java lookbehinds. The workaround you proposed makes the finite length of the lookbehind explicit and looks very clever to me. I was intrigued to find out what Python does with this regex. Python only supports fixed-length lookbehind, not finite-length like Java, but … Read more
GNU sed does not have support for lookaround assertions. You could use a more powerful language such as Perl or possibly experiment with ssed which supports Perl-style regular expressions. perl -pe ‘s/(?<=foo)bar/test/g’ file.txt
VBA offers lookahead (both positive and negative) but rather inconsistently not lookbehind. The best example of using Regex with VBA that I have seen is this article by Patrick Matthews. [Updated example using Execute rather than Replace] While I am not completely clear on your usage you could use a function like this: It skips … Read more
Lookahead and lookbehind aren’t nearly as similar as their names imply. The lookahead expression works exactly the same as it would if it were a standalone regex, except it’s anchored at the current match position and it doesn’t consume what it matches. Lookbehind is a whole different story. Starting at the current match position, it … Read more
Many regular expression libraries do only allow strict expressions to be used in look behind assertions like: only match strings of the same fixed length: (?<=foo|bar|\s,\s) (three characters each) only match strings of fixed lengths: (?<=foobar|\r\n) (each branch with fixed length) only match strings with a upper bound length: (?<=\s{,4}) (up to four repetitions) The … Read more