I have this bit of code:
import re
word = 'baz'
regexp = re.compile(r'a[s|z|d]')
if regexp.search(word) is not None:
print 'matched'
else:
print 'not matched'
Which I got from SO. That works and prints matched. Now I am trying to get the same thing to work for a different regex which I've got working in PHP.
This /[a-zA-Z0-9_.-]+$ regex works to filter out these results
mixed_CASE_word_00008908908808908080 # correctly matches
word_with_characters_I_dont_want-(1) # correctly does not match
I want to change the above python code to do the same but I'm not familiar with python and I'm struggling. I've so far got:
import re
word = 'mixed_CASE_word_00008908908808908080'
regexp = re.compile(r'/[a-zA-Z0-9_.-]+$')
if regexp.search(word) is not None:
print 'matched'
else:
print 'not matched'
But this gives me the following result:
mixed_CASE_word_00008908908808908080 # not matched
word_with_characters_I_dont_want-(1) # not matched
And I want the code to produce this result
mixed_CASE_word_00008908908808908080 // matched
word_with_characters_I_dont_want-(1) // not matched
Any ideas where I am going wrong?
a[s|z|d]matchesa|also.a[szd]if you actually meanasorazorad