user3587624
user3587624

Reputation: 1471

Regex - How can I exclude expressions with duplicated characters

I am awful trying to figure out Regex and I was wondering who I could achieve the following scenario...

Let's say my input is something like this.

|1 |2 ||3 ||312 |213

I would like to have a Regex that matches only the occurrences with one '|'. So basically, I want to match any text that contains one '|' and any amount of numbers after it...

I tried this one: [\|][0-9]+ but obviously it is also giving me ||3 and ||312 as matches.

Any help?

Thanks!

Upvotes: 0

Views: 102

Answers (1)

Avinash Raj
Avinash Raj

Reputation: 174696

Use negative lookbehind assertion.

(?<!\|)\|[0-9]+

(?<!\|) negative lookbehind which asserts that the match \|[0-9]+ won't be preceded by a pipe character.

DEMO

Upvotes: 5

Related Questions