“Python regex mendapatkan semua pertandingan” Kode Jawaban

Python regex mendapatkan semua pertandingan

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 .findall

  ## 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 temukan semua kalimat 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

Jawaban yang mirip dengan “Python regex mendapatkan semua pertandingan”

Pertanyaan yang mirip dengan “Python regex mendapatkan semua pertandingan”

Lebih banyak jawaban terkait untuk “Python regex mendapatkan semua pertandingan” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya