I’m wondering if variable length lookbehind assertions are supported in JavaScript’s RegExp engine?
For example, I’m trying to match the string “variable length” in the string “[a lot of whitespaces and/or tabs]variable length lookbehind“, and I have something like this but it does not go well in various RegExp testers:
^(?<=[ \t]+).+(?= lookbehind)
If it’s an illegal pattern, what would be a good workaround to it? Thanks!
Javascript doesn’t have look-behind at all. Steven Levithan has written up a few says to sort of mimic it, which may be helpful.
I don’t quite understand your example, because it seems as though this would fit the bill:
…which matches one or more whitespace chars followed by one or more of any character (in a capture group) followed by the word “lookbehind”. Used like this:
yields this array:
In Javascript, the first entry in the array is the entire matched string, and the subsequent entries are the capture groups.
But you clearly have a good grasp of regex, so I’m not sure that’s what you’re looking for…
Something to be aware of in this general area is that a number of implementations of RegExp engines in Javascript don’t quite handle
\scorrectly (they miss out matching some whitespace chars above the ASCII range); see the S_REGEXP_WHITESPACE_CHARACTER_CLASS_BUGGY test here.