fork download
  1. import re
  2. numeric_regex = r'''
  3. [-+]? # pos or neg
  4. (?:
  5. \d*\.\d+ # float (ie .1 and 1.1)
  6. |
  7. \d+ \.? # int (with trailing periods ie 1.)
  8. )'''
  9.  
  10. default_regex = rf'''
  11. \|.*? # | and 0+ whitespaces
  12. ({numeric_regex}) # Capturing group: all digits
  13. $ # end of the string
  14. '''
  15. logic = 'xxx -> 31223.1 | xxx 1.1'
  16. m = re.search(default_regex, logic, re.VERBOSE)
  17. if m:
  18. print(m.group(1))
Success #stdin #stdout 0.02s 9460KB
stdin
Standard input is empty
stdout
1.1