user746317
user746317

Reputation: 35

Weird in a regular expression

I tried the following regular expression:

Pattern: ((.[^[0-9])+)(([0-9]{1,3}([.][0-9]{3})+)|([0-9]+))

My goal is to match any string (excluding digit number) followed by a specified number, e.g. MG2999, dasdassa33232

I used the above regular expression.

It's weird as follows:

V375 (not matched)

Vv375 (matched)

Vvv375 (not matched, but first character is not matched)

Vvvv375 (matched)

...

I don't understand why the first character is never matched. May I need your help?

For your quick test, please try: http://regex101.com/

Thanks in advance!

-- Vu

Upvotes: 0

Views: 56

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545588

(.[^[0-9])+) matches any character (.), followed by any character except digits and [, repeatedly.

You probably want [^0-9]+ here – or, simpler, \D+.

The rest of there regular expression has similar problems but since I don’t know the number format you want to match I cannot correct that.

Upvotes: 1

Related Questions