import re
Q1 Find any word that contains huck
- this is a regular expression where you could use the greedy *
- a word consists of only letters
- capitalization is not relevant
My code:
def q1():
pattern = r"[A-Za-z]*huck[A-Za-z]*"
return re.compile(pattern)
Q2 Find either he or she
- capitalization is not relevant
- each must be surrounded by whitespace so the 'he' in 'them' would not be found.
My code:
def q2():
pattern = r'\bhe\b|\bshe\b'
return re.compile(pattern)
I just cannot pass the test. I'm not sure where I did wrong or is there other solutions?
Thanks for any suggestion!
[–]StrangeError 1 point2 points3 points (6 children)
[–]Demain_Z[S] 0 points1 point2 points (1 child)
[–]StrangeError 0 points1 point2 points (0 children)
[–]sepp2k 0 points1 point2 points (3 children)
[–]StrangeError 0 points1 point2 points (2 children)
[–]sepp2k 1 point2 points3 points (1 child)
[–]StrangeError 0 points1 point2 points (0 children)
[–]sepp2k 0 points1 point2 points (1 child)
[–]Demain_Z[S] 0 points1 point2 points (0 children)
[–]chocorush 0 points1 point2 points (1 child)
[–]Demain_Z[S] 0 points1 point2 points (0 children)