0

I have the following example text:

60CC
60 cc
60cc2
60CC(2)

and the following regex to match these instances:

(60\s?(cc)(\w|\(.\)){0,5})

however my output is as follows for the first match:

    Match 1
1.  60CC
2.  CC
3.  None

this example can be seen at: https://pythex.org/?regex=(60%5Cs%3F(cc)(%5Cw%7C%5C(.%5C))%7B0%2C5%7D)&test_string=60CC%0A60%20cc%0A60cc2%0A60CC(2)&ignorecase=1&multiline=0&dotall=0&verbose=0

how do I limit the output to just #1 ?

I am using Python Regex. the snippet of my python code is:

re.findall("(60\s?(cc)(\w|\(.\)){0,5})", text, flags=re.IGNORECASE)
qbbq
  • 301
  • 1
  • 11

1 Answers1

2

how do I limit the output to just #1 ?

You can just ignore the irrelevant groups from your findall/finditer results.

Alternatively, use non-capturing groups for the bits you don't care about: just add ?: after the leading parenthesis, this way you can still use grouping features (e.g. alternation) without the group being captured (split out) in the result.

Masklinn
  • 23,560
  • 2
  • 21
  • 39