iguanaman
iguanaman

Reputation: 1040

How do I find a group that does not match a set of accepted phrases

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

Answers (2)

Arsen Y.M.
Arsen Y.M.

Reputation: 697

{(?!(offer_id|offer_name)).*?}

Upvotes: 0

anubhava
anubhava

Reputation: 785856

Problem is that you are matching } without matching any character after {.

You should use:

{(?!(?:offer_id|offer_name)})[^}]*}

Updated Regex Demo

[^}]* will match 0 or more of any character that is not } before matching }.

Upvotes: 1

Related Questions