javascript - match multi line string with reguar exprssions and sticky flag in JS -
i trying match multi line string following pattern: $[any characters]$$[any characters]$ can preceded characters , followed number of characters. should match if there new line in [any characters]
what have done far is:
/\$.*\$\$.*\$/myg this finds correct match if it's @ start , add whole line if added 1 $ after first match not require y(sticky flag). also, though added right flags, doesn't match in new lines.
i find index of each match , store whole matches in array process , find [any characters] , replace whole match first part of it.
i happy hints or guide. in advance
it seems need match $ followed chars other $ $$ substring, , again chars other $ first $. use
/\$[^$]*\$\$[^$]*\$/g see regex demo
note m modifier not here since have no ^ , $ anchors in pattern. m make ^ match start of line rather start of string, , $ match end of line. y sticky modifier make regex match once @ current regexp.lastindex, matches, need remove , use g. see this regexp.prototype.sticky reference:
a regular expression defined both
sticky,globalignoresglobalflag.
pattern details
\$- single$char[^$]*- 0+ chars other$\$\$- 2 consecutive$symbols[^$]*- 0+ chars other$\$-$.
Comments
Post a Comment