Reputation: 1040
How can I search the following url for instances of {thing} that are not phrases that I allow?
Test string;
https://example.com?good={offer_id}&good2={offer_name}&bad={revenue}&extra=1
{offer_id} and {offer_name} should NOT match {revenue} should match
The closest pattern I came up with is (but no matches);
/{(?!(offer_id|offer_name))}/
In online regex tester: https://regex101.com/r/HwSknv/1
EDIT1: I want to match each instance of {revenue} (or similar). As I intended to replace them out.
Upvotes: 1
Views: 150
Reputation: 785856
Problem is that you are matching }
without matching any character after {
.
You should use:
{(?!(?:offer_id|offer_name)})[^}]*}
[^}]*
will match 0 or more of any character that is not }
before matching }
.
Upvotes: 1