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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -