Regex Javascript to catch string -


i using regex ^(?:foo|bar)+|(.+)$ catch string different 'foo' or 'bar' catches string after foo or bar , not @ beginning. example catches ba in string foobarfooba doesn't catch ba in string bafoobarfoo.

demo

because used start of line anchor. removing start of line anchor won't work you. suggest use below regex.

var s = "bafoobar";  var re = /foo|bar|((?:(?!foo|bar).)+)/gm;  alert(re.exec(s)[1])

demo


Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -