الدالة re.purge()‎ في بايثون‎

من موسوعة حسوب
< Python‏ | re

تفرغ هذه الدالة الذاكرة المخبئية cache الخاصة بالتعبير النظامي.

البنية العامة

re.purge()

القيمة المعادة

لا تعيد هذه الدالة أي قيمة.

يمكن الوصول إلى الذاكرة المخبئية الخاصّة بالتعابير النظامية عن طريق المتغيّر الخاص ‎_cache وهو عبارة عن قاموس يجمع التعابير النمطية المستخدمة سابقًا.

أمثلة

يبين المثال التالي طريقة استخدام هذه الدالة:

>>> p = re.compile(r'(?P<word>\b\w+\b)', re.IGNORECASE)
>>> re._cache
{(<class 'str'>, '[ ]*', 0): (re.compile('[ ]*'), None), (<class 'str'>, '^(\\s*
def\\s)|(\\s*async\\s+def\\s)|(.*(?<!\\w)lambda(:|\\s))|^(\\s*@)', 0): (re.compi
le('^(\\s*def\\s)|(\\s*async\\s+def\\s)|(.*(?<!\\w)lambda(:|\\s))|^(\\s*@)'), No
ne), (<class 'str'>, '[ \\f\\t]*((\\\\\\r?\\n|\\Z|#[^\\r\\n]*|((|Br|f|U|r|Fr|F|R
|rb|br|Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|B|BR|u|rf|fr)\'\'\'|(|Br|f|U|r|Fr|F|R|rb|br|
Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|B|BR|u|rf|fr)"""))|(([0-9](?:_?[0-9])*[jJ]|(([0-9](
?:_?[0-9])*\\.(?:[0-9](?:_?[0-9])*)?|\\.[0-9](?:_?[0-9])*)([eE][-+]?[0-9](?:_?[0
-9])*)?|[0-9](?:_?[0-9])*[eE][-+]?[0-9](?:_?[0-9])*)[jJ])|(([0-9](?:_?[0-9])*\\.
(?:[0-9](?:_?[0-9])*)?|\\.[0-9](?:_?[0-9])*)([eE][-+]?[0-9](?:_?[0-9])*)?|[0-9](
?:_?[0-9])*[eE][-+]?[0-9](?:_?[0-9])*)|(0[xX](?:_?[0-9a-fA-F])+|0[bB](?:_?[01])+
|0[oO](?:_?[0-7])+|(?:0(?:_?0)*|[1-9](?:_?[0-9])*)))|((\\*\\*=?|>>=?|<<=?|!=|//=
?|->|[+\\-*/%&@|^=<>]=?|~)|[][(){}]|(\\r?\\n|\\.\\.\\.|[:;.,@]))|((|Br|f|U|r|Fr|
F|R|rb|br|Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|B|BR|u|rf|fr)\'[^\\n\'\\\\]*(?:\\\\.[^\\n
\'\\\\]*)*(\'|\\\\\\r?\\n)|(|Br|f|U|r|Fr|F|R|rb|br|Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|
B|BR|u|rf|fr)"[^\\n"\\\\]*(?:\\\\.[^\\n"\\\\]*)*("|\\\\\\r?\\n))|\\w+)', <RegexF
lag.UNICODE: 32>): (re.compile('[ \\f\\t]*((\\\\\\r?\\n|\\Z|#[^\\r\\n]*|((|Br|f|
U|r|Fr|F|R|rb|br|Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|B|BR|u|rf|fr)\'\'\'|(|Br|f|U|r|Fr|
F|R|rb|br|Rb|Rf|FR|rB|RF|rF|fR|b|bR|RB|B|BR|u|rf|fr)"""))|(([0-9](?:_?[), None),
 (<class 'str'>, '^ *\n', 0): (re.compile('^ *\n'), None), (<class 'str'>, '\\s+
', 0): (re.compile('\\s+'), None), (<class 'str'>, '(?s:\\(\\\\.*)\\Z', 0): (re.
compile('(?s:\\(\\\\.*)\\Z'), None), (<class 'str'>, '(?s:\\(\\\\w.*)\\Z', 0): (
re.compile('(?s:\\(\\\\w.*)\\Z'), None), (<class 'str'>, '(?s:\\(\\\\w\\).*)\\Z'
, 0): (re.compile('(?s:\\(\\\\w\\).*)\\Z'), None), (<class 'str'>, '(?s:\\(\\\\w
\\)\\+.*)\\Z', 0): (re.compile('(?s:\\(\\\\w\\)\\+.*)\\Z'), None), (<class 'str'
>, '(?s:\\(\\\\w\\)\\+\\(.*)\\Z', 0): (re.compile('(?s:\\(\\\\w\\)\\+\\(.*)\\Z')
, None), (<class 'str'>, '(?s:\\(\\\\w\\)\\+\\(\\\\.*)\\Z', 0): (re.compile('(?s
:\\(\\\\w\\)\\+\\(\\\\.*)\\Z'), None), (<class 'str'>, '(?s:\\(\\\\w\\)\\+\\(\\\
\d.*)\\Z', 0): (re.compile('(?s:\\(\\\\w\\)\\+\\(\\\\d.*)\\Z'), None), (<class '
str'>, '(?s:\\(\\\\w\\)\\+\\(\\\\d\\).*)\\Z', 0): (re.compile('(?s:\\(\\\\w\\)\\
+\\(\\\\d\\).*)\\Z'), None), (<class 'str'>, '(?s:\\(\\\\w\\)\\+\\\\\\(\\\\d\\).
*)\\Z', 0): (re.compile('(?s:\\(\\\\w\\)\\+\\\\\\(\\\\d\\).*)\\Z'), None), (<cla
ss 'str'>, '(?s:\\(\\\\w\\)\\+\\\\\\:\\(\\\\d\\).*)\\Z', 0): (re.compile('(?s:\\
(\\\\w\\)\\+\\\\\\:\\(\\\\d\\).*)\\Z'), None), (<class 'str'>, '(\\w)+\\:(\\d)',
 0): (re.compile('(\\w)+\\:(\\d)'), None), (<class 'str'>, 'p\\ \\=\\ ', 0): (re
.compile('p\\ \\=\\ '), None), (<class 'str'>, '(?P<word>\\b\\w+\\b)', <RegexFla
g.IGNORECASE: 2>): (re.compile('(?P<word>\\b\\w+\\b)', re.IGNORECASE), None)}
>>> re.purge()
>>> re._cache
{(<class 'str'>, '[ ]*', 0): (re.compile('[ ]*'), None)}

مصادر