-1

I want a pattern which can match both of these expressions:

expr1 = `a + b` 
expr1 = `a+b`

Thanks.

1 Answers1

1

try this:

`(\w+)\s*(\S)\s*(\w+)`

first hit gets you the first variable (a), second hit gets you the operand (+) and third hit gets you the second variable (b)
Works also for python
Edit:
resowing the backticks and here's a regex checker for you: https://regex101.com/r/Hy1vSl/1

user2141046
  • 862
  • 2
  • 7
  • 21