re.ASCII

Full name
re.ASCII
Library
re
Syntax

re.ASCII

Description

The re.ASCII search modifier forces the symbols \w, \W, \b, \B, \d, \D, \s, and \S to rely on ASCII code to find text matches, rather than in Unicode.

Parameters

The re.ASCII search modifier takes no arguments.

Examples

If we start from the following text and regular expression:

text = "la cigüeña es bonita" # the stork is pretty
pattern = r"\w+"

...searching for all matches of the search pattern with re.findall returns, by default, the following result:

re.findall(pattern, text)
['la', 'cigüeña', 'es', 'bonita']

If we force the ASCII code to be considered for the identification of matches, the result changes:

re.findall(pattern, text, flags = re.ASCII)
['la', 'cig', 'e', 'a', 'es', 'bonita']
Submitted by admin on Wed, 05/19/2021 - 08:30