Regex of +|- return null

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By muncuss

Hello, i am trying to find either + or - in a string like “apple + 6” with regex.compile(“+|-”) but return null. maybe it needs escape character but im trying with \+|- it said invalid escape sequence. tried to double it (“\\+|-”) only worked once and now it returns also null

:bust_in_silhouette: Reply From: jgodfrey

Both of those characters need to be escaped. So, something like this should work:

var regex =
var string = "apple + 6"
var result =
if result:

thanks for the answer but i just realized i put the wrong string variable lol

muncuss | 2022-02-03 12:19