

Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!


Use To match any character [ set ] In that set [^ set ] Not in that set [ a–z ] In the a-z range [^ a–z ] Not in the a-z range
. Any except \n (new line) ** char Escaped special character
Use To match Unicode \t Horizontal tab \u \v Vertical tab \u000B \b Backspace \u \e Escape \u001B \r Carriage return \u000D \f Form feed \u000C \n New line \u000A \a Bell (alarm) \u
*Use To match character with * octal First digit 0 followed by 2 octal digits or 3 octal digits \x hex 2 - digit hex character code \u hex 4 - digit hex character code
Use To match character \w Word character. [0-9_a-zA-Z] and Unicode word characters \W Non-word character \d Decimal digit and Unicode digits \D Not a decimal digit \s White-space character [ \t\n\r\f\v] and Unicode spaces \S Non-white-space char
**Greedy Lazy Matches
Use To specify position ^ At start of string or line \A At start of string \Z At end of string $ At end of string or line \b On word boundary \B Not on word boundary
Use To define ( exp ) Indexed group (?P< name > exp ) Named group (?: exp ) Noncapturing group (?= exp ) Zero-width positive lookahead (?! exp ) Zero-width negative lookahead (?<= exp ) Zero-width positive lookbehind. exp is fixed width (?<! exp ) Zero-width negative lookbehind. exp is fixed width
Option Effect on match i Case-insensitive m Multiline mode L Locale specific u Unicode dependent s Single-line mode x Ignore white space Updated: November 2019 Chandra Lingam, Cloud Wave LLC https://github.com/ChandraLingam/PyRegex Template: Microsoft/MSDN .NET Regular Expressions Python Reference: re module documentation
*Use To match * n Indexed group (?P= name ) Named group
Use To match a | b Either a or b (?( n ) yes | no ) yes if group n is matched no if group n isn't matched (?( name ) yes | no ) yes if name is matched no if name isn't matched
Use To substitute \g< n > Substring matched by group number n \g< name > Substring matched by group name
Use To (?# comment ) Add inline comment # Add x-mode comment to end
Module: re Pattern matching with Compiled objects To initialize with Use constructor Pattern re.compile(pattern)