FabianCook
FabianCook

Reputation: 20557

Using regex is picking up on plus symbols when it shouldn't

I have this regex here:

"\d+.?\d*\^\d+\.?\d*"

What it should be doing is finding something like 2^10 in a string like 1*1+2^10*1 but it comes back with 1+2^10.

What am I doing wrong? I assume it is something to do with the .?

Upvotes: 3

Views: 807

Answers (1)

Stefan Seemayer
Stefan Seemayer

Reputation: 2067

In regular expressions, the . character stands for "match any character". You will have to escape it:

"\d+\.?\d*\^\d+\.?\d*"

You can try out your regular expression using RegexPal

Upvotes: 6

Related Questions