regular expression ignore sign of digit

i’m learning regular expressions at the moment and I try to grab a floating-point number. I like to discard all characters in front and back of the first floating-point number.
at the moment I have this expression:

[sw]*([-+]{0,1}d*[,.]{0,1}d*)

and here are the cases that I like to match (the lines with an X are nit working)

'1,2'    ->  1,2  
'1.2'    ->  1,2  X  
'abc1,2' ->  1,2  
'   1,2' ->  1,2  
'  +1,2' -> +1,2  
'  -1,2' -> -1,2  
' --1,2' -> -1,2  X  
' +-1,2' -> -1,2  X  
' -+1,2' -> +1,2  X  

How to ignore the second sign in front of the digit?


Source: regex

Leave a Reply