regex. Match all words starting with two letter
I wish to find all words that start with "Am" and this is what I tried so far with python import re my_string = "America's mom, American" re.findall(r'\b[Am][a-zA-Z]+\b', my_string) but this is the output that I get ['America', 'mom', 'American'] Instead of what I want ['America', 'American'] I know that in regex [Am] means match either A or m, but is it possible to match A and m as well?
The [Am], a positive character class, matches either A or m. To match a sequence of chars, you need to use them one after another. Remove the brackets: import re my_string = "America's mom, American" print(re.findall(r'\bAm[a-zA-Z]+\b', my_string)) # => ['America', 'American'] See the Python demo This pattern details: \b - a word boundary Am - a string of chars matched as a sequence Am [a-zA-Z]+ - 1 or more ASCII letters \b - a word boundary.
Don't use character class: import re my_string = "America's mom, American" re.findall(r'\bAm[a-zA-Z]+\b', my_string)
re.findall(r'(Am\w+)', my_text, re.I)
Is it safe to use scipy.sparse functions with Pandas sparse dataframes?
I got error : UnboundLocalError: local variable 'porc' referenced before assignment
Trigger a delete when inserting a new entry on django
How does gauss laguerre integration works for large limits?
Selenium: Runtime.executionContextCreated has invalid 'context':
Python 3.5 csv input shows extra character 'b'
Python Error 104, connection reset by peer
css not getting loaded in flask webpage?
Regarding the regex in search module with and without raw text
How to calculate the mean of a column by decade in Python
How to read webpages that are without .htm* extension using Python?
can I use python's 'socket' module to connect to a wireless ethernet host?
Requests VS Urllib 2 [closed]
Call python class from another Python script
How can I use BeautifulSoup to get a few contents that comes after a specific text on a page?
Reinstall python 2.7.12 and python 3.5.2