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

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

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -