“python regex obtient tous les matchs” Réponses codées

python regex obtient tous les matchs

re.findall( r'all (.*?) are', 'all cats are smarter than dogs, all dogs are dumber than cats')
# Output: ['cats', 'dogs']

[x.group() for x in re.finditer( r'all (.*?) are', 'all cats are smarter than dogs, all dogs are dumber than cats')]
# Output: ['all cats are', 'all dogs are']
Crowded Cod

Python.

  ## Search for pattern 'bb' in string 'aabbcc'.
  ## All of the pattern must match, but it may appear anywhere.
  ## On success, match.group() is matched text.
  match = re.search(r'bb', 'aabbcc') # found, match.group() == "bb"
  match = re.search(r'cd', 'aabbcc') # not found, match == None

  ## . = any char but \n
  match = re.search(r'...c', 'aabbcc') # found, match.group() == "abbc"

  ## \d = digit char, \w = word char
  match = re.search(r'\d\d\d', 'p123g') # found, match.group() == "123"
  match = re.search(r'\w\w\w', '@@abcd!!') # found, match.group() == "abc"
Colorful Capuchin

regex trouver toutes les phrases python

text = "This is a good sentence. This is another good 1! thanks"

sentences = re.findall(r"[A-Z].*?(\.\s|\?\s|\!\s)", text)
Control C Control V

Réponses similaires à “python regex obtient tous les matchs”

Questions similaires à “python regex obtient tous les matchs”

Plus de réponses similaires à “python regex obtient tous les matchs” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code