Simple regex help

smaker

Newbie
Joined
Jan 13, 2010
Messages
12
Reaction score
0
I'm trying to seperate the following string

"200 + 99 = ?"

I want to create a regex to catch the 200. Right now I have .*(?=\+) but how do I specifiy that the + could also be a minus?
 
why u using Regex is for advanced Match just Use Split Function if you want to get 200 form that string & use delimeter as " " (Space)
 
"200 + 99 = ?"

Regex: (\d*).*(\+|-)

(\d*) = Group matching any number
.* = Match any character between the two groups (useful in case there isn't whitespace)
(\+|-) = Group matching either + or -

Matches = 200 +
Group 1 = 200
Group 2 = +
 
why u using Regex is for advanced Match just Use Split Function if you want to get 200 form that string & use delimeter as " " (Space)

Makes sense so much easier too, I figured it out shortly after anyway

"200 + 99 = ?"

Regex: (\d*).*(\+|-)

(\d*) = Group matching any number
.* = Match any character between the two groups (useful in case there isn't whitespace)
(\+|-) = Group matching either + or -

Matches = 200 +
Group 1 = 200
Group 2 = +
Thanks
 
Back
Top