javascript - regexp excluye char -


i trying create regexp has following characteristics.

  1. begin {{
  2. may contain line breaks , character
  3. 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 followed hello# , followed 1+ characters other # , }
  • #hello# - #hello#.

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -