-1

I have the following string and need to match the continuous numeric part. i.e. matching will fail if a non-numeric character is in the middle of the numeric part

I know I can write a for loop a iterate through each character, but is it possible with regex alone?

the numeric part 00000 will match in these

AAA00000BBB
00000BBB
AAA00000

these will not match

AAA00X00BBB
00X000
Jasmine
  • 153
  • 8
  • Possible duplicate of [Learning Regular Expressions](http://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Jan 14 '17 at 15:33

1 Answers1

2

This one should do the job:

^\D*(\d+)\D*$

Explanation:

^       : begining of string
  \D*   : 0 or more non digit
  (\d+) : 1 or more digit, captured in group 1
  \D*   : 0 or more non digit
$       : end of string
Toto
  • 83,193
  • 59
  • 77
  • 109