i have a problem with my python script, i want to make some regex function. Now i've done make it but how to detect if the string is matched with some patterns ?
I give an example, i have one string and two patterns of regex. Now how do i know if the string is matched with first pattern or second pattern ?
This is my script.
#!/usr/bin/python
import re
words = ["(@sosiora\*+([1-5]*)(\W|)+(@[a-z]*)(\W|))",
"((@[a-z]*)(\W|)@sosiora\*+([1-5]*)+(\W|))"
]
pattern = re.compile('|'.join(words), flags=re.IGNORECASE)
text = "@sosiora*4 @samsungID"
m = pattern.findall(text)
print m;
if m:
if len(m[0][1]) > 1:
print 'Rating is not accepted : ' +m[0][1]
print 'String: ' + text
else :
print 'Found %d matches' % len(m)
print 'String: ' + text
print 'Rating: ' + m[0][1]
print 'Target: ' + m[0][3]
print 'Pattern: ' // this is output to show the pattern
else:
print 'rate is not found'
So, the output what i want is just Please help me, thank you.