1

I got a big text with a parenthesis and some text inside that needs parsing.

I successfully use this regex (\w+)\s*\:\s*(\(.*), to catch everything inside the parenthesis but the I need do another regex inside the result and this fails.

My code:

import re

txt = "COM: (ZZZ, Min: 2, Max: 114)\n"
txt+= "TESTING : BBB"
m = re.match(r'(\w+)\s*\:\s*(\(.*)', txt)

comm = str(m.group(2)).strip()
print(comm) #  Output: (ZZZ, Min: 2, Max: 114)

trk = re.match(r"\bMin", comm)
print(trk) # Output: None, should be "Min"

What am I doing wrong?

Antonis
  • 361
  • 2
  • 4
  • 11
  • @Barmar this is not the same like the question you suggested, If I comment out all the previous code and all that is left is the last regex again I get no result. – Antonis Jul 19 '18 at 03:24
  • 1
    All you have to do is change the second `re.match` to `re.search`. – Barmar Jul 19 '18 at 03:25
  • The other question explains that `re.match` only matches at the beginning. You're getting `None` because `Min` is not at the beginning of the string. – Barmar Jul 19 '18 at 03:25
  • @Barmar like this: trk = re.match(r"\bMin", '(ZZZ, Min: 2, Max: 114)') I get None again. So the problem might be on the regex – Antonis Jul 19 '18 at 03:25
  • You're still using the wrong function! – Barmar Jul 19 '18 at 03:26
  • Ok, thanks I will try – Antonis Jul 19 '18 at 03:26
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176299/discussion-between-antonis-and-barmar). – Antonis Jul 19 '18 at 03:29

0 Answers0