Rajeev
Rajeev

Reputation: 115

Using Regular expression to find out numbers in my text?

I have to find out all the numbers in my document which are in the format 1., 2.,3. etc i am using the regular expression [0-9]+.\. this is working fine with double digit numbers but having issue with the single digit numbers like 1. 2. can someone help me out with this one?

Upvotes: 0

Views: 70

Answers (2)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726509

The problem is the dot after the plus. Your regex will find things like 123x., because . matches anything:

123 x .
^^^ ^ ^
 |  | |
 |  | +-- \.
 |  +---- .
 +------- [0-9]+

Remove the first dot to fix this.

Upvotes: 5

Avinash Raj
Avinash Raj

Reputation: 174696

Remove the in-between unescaped dot. Because an unescaped dot in regex matches any character.

[0-9]+\.

Upvotes: 2

Related Questions