javascript - regexp excluye char -
i trying create regexp has following characteristics.
- begin {{
- may contain line breaks , character
- may not contain }}
example
**this ok.
{{ dog car blue #hello#
this not ok.
{{ dog car blue }} #hello#
i tried regexp:
{{2}([\s\s]*?)[^\{]#hello#
but returns ok
you need tempered greedy token solution because need first match multicharacter leading delimiter {{
, need match any text other #hello#
, {{
(multicharacter sequences). if had negate 1 character, [^{]
suffice. not case here.
use
/{{[^#}]*(?:}(?!})[^#}]*|#(?!hellow#)[^#}]*)*#hello#/g
see regex demo
note unrolled variant of {{(?:(?!}}|#hellow#)[\s\s])*#hello#
more readable highly inefficient , more prone catastrophic backtracking issue.
details:
{{
- matches{{
[^#}]*
- 0+ characters other#
,}
(?:}(?!})[^#}]*|#(?!hellow#)[^#}]*)*
- matches 0+ sequences of either}(?!})[^#}]*
-}
not followed}
, followed 1+ characters other#
,}
|
- or#(?!hellow#)[^#}]*
-#
not followedhello#
, followed 1+ characters other#
,}
#hello#
-#hello#
.
Comments
Post a Comment