Javascript Regex to match bounded text -


i have text this:

....foo..bar.... 

foo , bar can text @ all.

it be:

anypreamble....foo..bar....anypostamble 

i'm trying match foo , bar keep matching entire thing.

here's code:

var s = "this....aaaaaaaaaa..bbbbcd....that";  console.log(s.replace(/\.{4}.+\.{2}(.+)\.{4}/g, 'x')); 

i expect above give me: thisaaaaaaaaaaxthat, instead gives: thisxthat.

can help?

here's fiddle: https://jsfiddle.net/vfkzdg9y/1/

if want 2 strings (foo , bar) separated x, can use:

var s = "this....aaaaaaaaaa..bbbbcd....that";  console.log(s.replace(/[^\.]*\.{4}([^\.]+)\.{2}([^\.]+)\.{4}.*/g, '$1x$2')); 

yields

aaaaaaaaaaxbbbbcd

you use:

console.log(s.replace(/[^\.]*\.{4}(.+)\.{2}(.+)\.{4}.*/g, '$1x$2')); 

which yields

aaaaaaaaaaxbbbb.cd

for second example.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -