0

for example: if i match "1+2+1" use "/[0-9](\+|\-)[0-9](\1)[0-9]",it works,

but now i want to match "1+2-1", but the regex "/[0-9](\+|\-)[0-9][^(\1)][0-9]/" didn't work.

so how to match the "NOT \1"?

Jesus Slim
  • 13
  • 3

2 Answers2

1

You may try to use negative lookahead and don't match it if it's the same as first matched char. You can fiddle around with this expression; [0-9]([+-])[0-9](?:(?!\1)[+-])[0-9]

https://regex101.com/r/mSSSlJ/1

Lostfields
  • 1,364
  • 1
  • 12
  • 20
0

You can use this to match both of the text:

[0-9](\+|\-)[0-9](\1)*[+-][0-9]
CoderX
  • 302
  • 2
  • 6