regex - Extract all numbers from a string along with their signs - Python 2.7 -


how extract numbers along sign?

strings can these -1+110, +20-123 , +23-432-543

i using simple regular expression

event_book_value = re.findall('\d+', event_book_value) 

it returns numbers not return along signs.

add optional sign in front of number regex:

[+-]?\d+ 
  • [+-] - character set matches single + or -
  • ? - makes previous match 1 or 0 times
  • \d+ - 1 or more digits

see in action


Comments