Given a flexible string of regex pattern, I need to find all attributes attached.
Example string: /html/body/div[1]/div/a/(@title|@href)
It needs to return ['@title', '@href']
I did some research and created a regex pattern like this: /@\w+/g
Tried it on regex101 and it did seems to works: https://regex101.com/r/cO8lqs/9124
But when I coded it in python
import re
xpath = "/html/body/div[1]/div/a/(@title|@href)"
print(re.findall("/@\w+/g", xpath)) # should have been worked
It returns []
As mentioned above, it needs to return ['@title', '@href']
Did I missed something?
Rahmat Nazali Salimi :
As suggested by @FailSafe on the question's comment, turns out I need to change the regex pattern from /@\\w+/g to @\\w+.",
2019-03-24T09:37:43