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.
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])
Comments
Post a Comment