{"id":3327,"date":"2021-12-09T09:41:59","date_gmt":"2021-12-09T09:41:59","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=3327"},"modified":"2021-12-09T09:46:24","modified_gmt":"2021-12-09T09:46:24","slug":"python-regex-flags","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-flags\/","title":{"rendered":"Python Regex Flags"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the Python regex flags and how they change the behavior of the regex engine for pattern matching.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-python-regex-flags'>Introduction to the Python regex flags <a href=\"#introduction-to-the-python-regex-flags\" class=\"anchor\" id=\"introduction-to-the-python-regex-flags\" title=\"Anchor for Introduction to the Python regex flags\">#<\/a><\/h2>\n\n\n\n<p>The regular expression functions like <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-findall\/\">findall<\/a>, <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-finditer\/\">finditer<\/a>, <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-search\/\">search<\/a>, <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-match\/\">match<\/a>, <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-split\/\">split<\/a>, <a href=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-sub\/\">sub<\/a>, &#8230; have the parameter (<code>flags<\/code>) that accepts one or more regex flags. <\/p>\n\n\n\n<p>Since Python 3.6, regex flags are instances of the <code>RegexFlag<\/code> <a href=\"https:\/\/www.pythontutorial.net\/python-oop\/python-enumeration\/\">enumeration<\/a> class in the <code>re<\/code> module. The following table shows the available regex flags and their meanings:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Flag<\/th><th>Alias<\/th><th>Inline Flag<\/th><th>Meaning<\/th><\/tr><\/thead><tbody><tr><td><code>re.ASCII<\/code><\/td><td><code>re.A<\/code><\/td><td><code>?m<\/code><\/td><td>The <code>re.ASCII<\/code> is relevant to the byte patterns only. It makes the <code>\\w<\/code>, <code>\\W<\/code>,<code>\\b<\/code>, <code>\\B<\/code>, <code>\\d<\/code>, \\D, and <code>\\S<\/code> perform ASCII-only matching instead of full Unicode matching.<\/td><\/tr><tr><td><code>re.DEBUG<\/code><\/td><td>N\/A<\/td><td>N\/A<\/td><td>The <code>re.DEBUG<\/code> shows the debug information of compiled pattern.<\/td><\/tr><tr><td><code>re.IGNORECASE<\/code><\/td><td><code>re.I<\/code><\/td><td><code>?i<\/code><\/td><td>perform case-insensitive matching. It means that the <code>[A-Z]<\/code> will also match lowercase letters.<\/td><\/tr><tr><td><code>re.LOCALE<\/code><\/td><td><code>re.L<\/code><\/td><td><code>?L<\/code><\/td><td>The <code>re.LOCALE<\/code> is relevant only to the byte pattern. It makes the <code>\\w<\/code>, <code>\\W<\/code>, <code>\\b<\/code>, <code>\\B<\/code> and case-sensitive matching dependent on the current locale. The <code>re.LOCALE<\/code> is not compatible with the <code>re.ASCII<\/code> flag.<\/td><\/tr><tr><td><code>re.MUTILINE<\/code><\/td><td><code>re.M<\/code><\/td><td><code>?m<\/code><\/td><td>The <code>re.MULTILINE<\/code> makes the <code>^<\/code> matches at the beginning of a string and at the beginning of each line and <code>$<\/code> matches at the end of a string and at the end of each line.<\/td><\/tr><tr><td><code>re.DOTALL<\/code><\/td><td><code>re.S<\/code><\/td><td><code>?s<\/code><\/td><td>By default, the dot (<code>.<\/code>) matches any characters except a newline. The <code>re.DOTALL<\/code> makes the dot (<code>.<\/code>) matches all characters including a newline.<\/td><\/tr><tr><td><code>re.VERBOSE<\/code><\/td><td><code>re.X<\/code><\/td><td><code>?x<\/code><\/td><td>The <code>re.VERBOSE<\/code> flag allows you to organize a pattern into logical sections visually and add comments.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>To combine two or more flags, you use the <code>|<\/code> operator like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">re. A | re.M | re.S<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='python-regex-flags'>Python regex flags  <a href=\"#python-regex-flags\" class=\"anchor\" id=\"python-regex-flags\" title=\"Anchor for Python regex flags \">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the Python regex flags.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-the-re-ignorecase-flag-example'>1) The re.IGNORECASE flag example <a href=\"#1-the-re-ignorecase-flag-example\" class=\"anchor\" id=\"1-the-re-ignorecase-flag-example\" title=\"Anchor for 1) The re.IGNORECASE flag example\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the <code>findall()<\/code> function to match all lowercase characters in the set <code>[a-z]<\/code> in a string:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'Python is awesome'<\/span>\npattern = <span class=\"hljs-string\">'&#91;a-z]+'<\/span>\n\nl = re.findall(pattern, s)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'ython'<\/span>, <span class=\"hljs-string\">'is'<\/span>, <span class=\"hljs-string\">'awesome'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Note that the letter <code>P<\/code> is not included in the result because it is not in the set <code>[a-z]<\/code>.<\/p>\n\n\n\n<p>The following example uses the <code>re.INGORECASE<\/code> flag:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'Python is awesome'<\/span>\npattern = <span class=\"hljs-string\">'&#91;a-z]+'<\/span>\n\nl = re.findall(pattern, s, re.IGNORECASE)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'Python'<\/span>, <span class=\"hljs-string\">'is'<\/span>, <span class=\"hljs-string\">'awesome'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Even though the pattern matches only characters in the set <code>[a-z]<\/code>, the <code>re.IGNORECASE<\/code> flag instructs the regex engine to also match characters in <code>[A-Z]<\/code> set.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='2-the-re-multiline-flag-example'>2) The re.MULTILINE flag example  <a href=\"#2-the-re-multiline-flag-example\" class=\"anchor\" id=\"2-the-re-multiline-flag-example\" title=\"Anchor for 2) The re.MULTILINE flag example \">#<\/a><\/h3>\n\n\n\n<p>The following example uses the ^ anchor to match one or more word characters at the beginning of a string:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'''Regex \nFlags'''<\/span>\n\npattern =<span class=\"hljs-string\">'^\\w+'<\/span>\n\nl = re.findall(pattern,s)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'Regex'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The s string has two lines. The <code>^<\/code> only match at the beginning of the string as expected.<\/p>\n\n\n\n<p>If you use the <code>re.MULTILINE<\/code> flag, the <code>^<\/code> will match at the beginning of each line. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'''Regex \nFlags'''<\/span>\n\npattern = <span class=\"hljs-string\">'^\\w+'<\/span>\n\nl = re.findall(pattern, s, re.MULTILINE)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'Regex'<\/span>, <span class=\"hljs-string\">'Flags'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='3-the-re-dotall-flag-example'>3) The re.DOTALL flag example <a href=\"#3-the-re-dotall-flag-example\" class=\"anchor\" id=\"3-the-re-dotall-flag-example\" title=\"Anchor for 3) The re.DOTALL flag example\">#<\/a><\/h3>\n\n\n\n<p>In this example, the dot <code>.+<\/code> pattern match one or more characters except for the new line:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'''Regex\nFlags'''<\/span>\n\npattern = <span class=\"hljs-string\">'.+'<\/span>\n\nl = re.findall(pattern, s)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'Regex'<\/span>, <span class=\"hljs-string\">'Flags'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>If you use the <code>re.DOTALL<\/code> flag, the <code>.+<\/code> will also match the new line:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'''Regex\nFlags'''<\/span>\n\npattern = <span class=\"hljs-string\">'.+'<\/span>\n\nl = re.findall(pattern, s, re.DOTALL)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'Regex\\nFlags'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='4-the-re-verbose-flag-example'>4) The re.VERBOSE flag example <a href=\"#4-the-re-verbose-flag-example\" class=\"anchor\" id=\"4-the-re-verbose-flag-example\" title=\"Anchor for 4) The re.VERBOSE flag example\">#<\/a><\/h3>\n\n\n\n<p>The following example shows how to use the <code>re.VERBOSE<\/code> flag to write a pattern in sections with comments:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'Python 3'<\/span>\n\npattern = <span class=\"hljs-string\">r'''^(\\w+) # match one or more characters at the beginning of the string\n               \\s*   # match zero or more spaces\n              (\\d+)$ # match one or more digits at the end of the string'''<\/span>\n\nl = re.findall(pattern, s, re.VERBOSE)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;(<span class=\"hljs-string\">'Python'<\/span>, <span class=\"hljs-string\">'3'<\/span>)]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the <code>re.VERBOSE<\/code> flag allows us to add spaces and comments to the regular expression to explain each individual rule.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='5-the-re-ascii-flag-example'>5) The re.ASCII flag example <a href=\"#5-the-re-ascii-flag-example\" class=\"anchor\" id=\"5-the-re-ascii-flag-example\" title=\"Anchor for 5) The re.ASCII flag example\">#<\/a><\/h3>\n\n\n\n<p>The following example matches words with two characters:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'\u4f5c\u6cd5 is Pythonic in Japanese'<\/span>\npattern = <span class=\"hljs-string\">r'\\b\\w{2}\\b'<\/span>\n\nl = re.findall(pattern, s)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-17\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'\u4f5c\u6cd5'<\/span>, <span class=\"hljs-string\">'is'<\/span>, <span class=\"hljs-string\">'in'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-17\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>However, if you use the <code>re.ASCII<\/code> flag, the matches will contain only ASCII characters:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-18\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> re\n\ns = <span class=\"hljs-string\">'\u4f5c\u6cd5 is Pythonic in Japanese'<\/span>\npattern = <span class=\"hljs-string\">r'\\b\\w{2}\\b'<\/span>\n\nl = re.findall(pattern, s, re.ASCII)\nprint(l)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-18\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-19\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">&#91;<span class=\"hljs-string\">'is'<\/span>, <span class=\"hljs-string\">'in'<\/span>]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-19\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, the word <code>\u4f5c\u6cd5<\/code> was excluded from the resulting list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The Python regex flags are instances of the RegexFlag enumeration class.<\/li><li>The regex flags change the way the regex engine performs pattern matching.<\/li><li>The regex functions like match, fullmatch, findall, finditer, search, split, sub, subn accept a flags parameter that can be a flag a combination of regex flags.<\/li><li>Use the | operator to combine two regex flags.<\/li><\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3327\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-flags\/\"\n\t\t\t\tdata-post-title=\"Python Regex Flags\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3327\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/python-regex\/python-regex-flags\/\"\n\t\t\t\tdata-post-title=\"Python Regex Flags\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>IIn this tutorial, you&#8217;ll learn about the Python regex flags and how they change the behavior of the regex engine for pattern matching.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":3122,"menu_order":21,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-3327","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=3327"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3327\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/3122"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=3327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}