rplaurindo rplaurindo - 1 year ago 87
Javascript Question

How to implement positive "lookbehind" of regular expressions in Javascript


Suppose the string

, i need capture in this case:

  • foo=bar

  • foo=foo

I did with
, see here.

But the Javascript doesn't support lookbehind, then the expression
(positive lookbehind) doesn't recognized.

I try too
(non capturing group syntax), but to execute the method
is returned:

  • ?foo=bar

  • &foo=foo

Answer Source

The solution was in our face. Sorry for my late.

The final regular expression was thus:


The especial character \b match a boundary word, then, for example, doesn't match: "nonfoo=bar", but match "foo", "foo=bar" and doesn't include nothing before "foo" (works it as positive lookbehind).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download