“Python Regex Split” Réponses codées

Expression régulière de la chaîne divisée Python

import re

s_nums = 'one1two22three333four'

print(re.split('\d+', s_nums))
# ['one', 'two', 'three', 'four']
SemicolonForgotten

Python re compile

import re
#	Compile a regular expression pattern into a regular expression object, which can be used for matching using its match(), search() and other methods, described below.

prog = re.compile(pattern)
result = prog.match(string)

#	is equivalent to

result = re.match(pattern, string)
Blushing Barracuda

Python Regex Split

import re

# Splitting will occurs only once, at '05', returned list will have length 2
print(re.split('\d+', 'On 05th Jan 1999, at 11:02 AM', 1))

# 'Boy' and 'boy' will be treated same when flags = re.IGNORECASE
print(re.split('[a-f]+', 'Aey, Boy oh boy, come here', flags=re.IGNORECASE))
print(re.split('[a-f]+', 'Aey, Boy oh boy, come here'))
Outrageous Ostrich

Python Regex Split Re.split () Syntaxe

re.split(pattern, string, maxsplit=0, flags=0)
Outrageous Ostrich

Réponses similaires à “Python Regex Split”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code