Regular expression to get the value after the comma

5

With the following expression (,) ([0-9] *) can get 25, but I would like to get only 25.

decimal (10.25)

In this case how do I disregard ,

    
asked by anonymous 12.07.2014 / 16:17

3 answers

7

If you just want to leave the number in a capture group, just take the comma from the parentheses:

,([0-9]*)
To ensure that you have some number you can use + instead of * (you can use \d instead of [0-9] if you want):

,(\d+)
    
12.07.2014 / 19:01
3

Use the following regular expression that will work:

(?<=,)([0-9]+)

This regular expression uses lookbehind that nothing else is to find the values of the set group ([0-9]+) if before it find the comma (?<=,) .

A full explanation of lookahead and lookbehind can be found on this site .

Here is a code example with Python:

import re
m = re.search('(?<=,)([0-9]+)', '(0,25)')
print m.group(0) #25
    
12.07.2014 / 20:00
-2

Just use (,25) , get all occurrences of, 25.

\w,(25*) for the whole number.

Test at Regexr

    
12.07.2014 / 16:42