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

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -