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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -