0

This is the first time I'm using regular expressions with python and I'm trying to figure out why it thinks the error "AttributeError: 'str' object has no attribute 'Match'"

I'm doing this in Jupyter notebook. What am I doing wrong here? I see only one other unhelpful question out there with this same missing attribute error.

import re
grp =  "Application: Company Name / 184010 - Application Development / 184010 - Contract Express"
rgx = "\w+ *(?!.*-)"
res = grp.match(rgx)
print(res)
5
  • 1
    Wrong syntax. Either re.match(rgx, grp) or re.compile(rgx).match(grp). Commented Apr 3, 2019 at 15:16
  • What are you trying to match here? Commented Apr 3, 2019 at 15:16
  • All words after the final dash @TimBiegeleisen Commented Apr 3, 2019 at 15:24
  • @meowgoesthedog thanks! Commented Apr 3, 2019 at 15:25
  • @TimBiegeleisenweirdly I'm not getting a match, the result is none yet in the regex tester I used it matches fine. Commented Apr 3, 2019 at 15:30

1 Answer 1

1

You want to use re.match but that starts at the beginning of the string. You could use findall instead:

import re
grp =  "Application: Company Name / 184010 - Application Development / 184010 - Contract Express"
rgx = "\w+ *(?!.*-)"
res = re.findall(rgx, grp)
print(res)  # ['Contract ', 'Express']

Python demo

If there should also not be a forward slash following, you could add that to a character class together with the hyphen.

Note that to not match the space after the word you could omit the space followed by the asterix * from the pattern.

\w+(?!.*[-/])

Regex demo | Python demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.