Java regex: Negative lookahead

Try String regex = “/foo/(?!.*bar).+”; or possibly String regex = “/foo/(?!.*\\bbar\\b).+”; to avoid failures on paths like /foo/baz/crowbars which I assume you do want that regex to match. Explanation: (without the double backslashes required by Java strings) /foo/ # Match “/foo/” (?! # Assert that it’s impossible to match the following regex here: .* # … Read more

Negative look-ahead in Go regular expressions

Negative lookahead isn’t supported for technical reasons, specifically because it conflicts with the O(n)-time guarantees of the library. See the golang-nuts group discussion about this, as well as the Caveats section in Regular Expression Matching in the Wild. You can express the regular expression you’ve described without negative lookahead: BBB([^B]|B[^B]|BB[^B])*EEE Here’s an example to demonstrate: … Read more

Python Regex Engine – “look-behind requires fixed-width pattern” Error

Python re lookbehinds really need to be fixed-width, and when you have alternations in a lookbehind pattern that are of different length, there are several ways to handle this situation: Rewrite the pattern so that you do not have to use alternation (e.g. Tim’s above answer using a word boundary, or you might also use … Read more