fork download
  1. import re
  2. s = ['-11.88', '<0.012541>', '-<3.14>', '<-2.98>', '<1.23', '<-abcdefg>']
  3. pat = re.compile(r'^[-+]?(?P<o><)?[-+0-9.Ee]+(?(o)>|)$')
  4. for i in s:
  5. res = pat.match(i)
  6. if res:
  7. print(i +': Match')
  8. else:
  9. print(i +': No match')
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
-11.88: Match
<0.012541>: Match
-<3.14>: Match
<-2.98>: Match
<1.23: No match
<-abcdefg>: No match