Reputation: 3668
I trying to implement lexer and trying to create regex what will match anything but not the following:
There is that i'm trying:
[^(<|{{|{%)]+
But it also does not watch ant single "{" and "%" symbols.
It it possible to do with regex?
Input: "foo {{ bar < baz {%" Output: "foo ", " bar ", "baz "
Upvotes: 2
Views: 207
Reputation: 786261
You can use lookaround based regex:
(?<=\s|^)(?!{[{%]|<)\S+
(?!{[{%])
is negative lookahead to match any non-space text that is not {{
or {%
.
Upvotes: 2
Reputation: 1714
I think you are writing a templating language and you may want to split on these characters, right? If so, then you split on the positive regex: (<|{{|{%)
Use http://www.regexr.com/ to learn more about regexes.
Upvotes: 1