{"id":847,"date":"2025-09-04T08:59:13","date_gmt":"2025-09-04T08:59:13","guid":{"rendered":"http:\/\/www.lexique.org\/?page_id=847"},"modified":"2025-09-04T08:59:14","modified_gmt":"2025-09-04T08:59:14","slug":"regular-expressions","status":"publish","type":"page","link":"http:\/\/www.lexique.org\/?page_id=847&lang=en","title":{"rendered":"Regular Expressions"},"content":{"rendered":"\n<p>Regular expressions, or <em>regex<\/em>, are &#8220;patterns&#8221; that allow you to search for words with certain properties. Here are some examples of regular expressions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ion<\/strong>: searches for words that contain the string &#8220;ion&#8221; in any position<\/li>\n<li><strong>ion$<\/strong>: words ending with &#8220;ion&#8221; (<strong>$<\/strong>=end of word)<\/li>\n<li><strong>^anti<\/strong>: searches for all words beginning with &#8220;anti&#8221; (<strong>^<\/strong>=beginning of word)<\/li>\n<li><strong>^house$<\/strong>: searches exactly for the word &#8220;house&#8221;<\/li>\n<li><strong>^p.*r$<\/strong>: words starting with &#8220;p&#8221; and ending with &#8220;r&#8221; (<strong>*<\/strong>=repetitions \u2013 0 or more \u2013 of the previous character, here &#8216;.&#8217;, meaning any character)<\/li>\n<li><strong>[aeiou][aeiou]<\/strong>: words containing (at least) 2 successive vowels (<strong>[]<\/strong>=character class; <strong>[abc]<\/strong> means the same as (a|b|c))<\/li>\n<li><strong>[ptkbdg][ptkbdg]<\/strong>: word containing a consonant cluster formed of plosives (search in the <em>phon<\/em> field)<\/li>\n<li><strong>oid|ion|ein<\/strong>: searches for words containing (at least) one of the three strings &#8220;iod&#8221;, &#8220;ion&#8221; or &#8220;ein&#8221; (<strong>|<\/strong>=or). For example, you can search for words that contain dog, cat or rabbit with the regex <em>dog|cat|rabbit<\/em><\/li>\n<li><strong>^(day|night|morning|evening)$<\/strong>: exactly the four words &#8220;day&#8221;, &#8220;night&#8221;, &#8220;morning&#8221; or &#8220;evening&#8221; (useful for searching a list of words)<\/li>\n<li><strong>p.t<\/strong>: searches for words containing a &#8220;p&#8221;, followed by any letter, then a &#8220;t&#8221; (the dot corresponds to any character)<\/li>\n<li><strong>^p&#8230;r$<\/strong>: words beginning with &#8220;p&#8221;, followed by three characters, and ending with &#8220;r&#8221; (the <strong>.<\/strong> symbol in a regex corresponds to any character)<\/li>\n<li><strong>^[aeiou]<\/strong>: words beginning with a vowel<\/li>\n<li><strong>^[aeiou]+$<\/strong>: words containing only vowels<\/li>\n<li><strong>^[^aeiou]<\/strong>: words not beginning with a vowel<\/li>\n<\/ul>\n\n\n\n<p>There are many tutorials on regex on the web, such as <a href=\"https:\/\/www.lucaswillems.com\/fr\/articles\/25\/tutoriel-pour-maitriser-les-expressions-regulieres\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"this page (opens in a new tab)\">this page<\/a> or <a rel=\"noreferrer noopener\" aria-label=\"this video (opens in a new tab)\" href=\"https:\/\/www.youtube.com\/watch?v=dinW2QTSNl4\" target=\"_blank\">this video<\/a>. The following course is also recommended: <a href=\"http:\/\/regextutorials.com\/intro.html\">http:\/\/regextutorials.com\/intro.html<\/a><br> <\/p>\n\n\n\n<p>The bible on regex is the book <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"http:\/\/regex.info\/book.html\" target=\"_blank\">Mastering Regular Expressions<\/a><\/p>\n\n\n\n<p>A regex describes a <a href=\"http:\/\/gallium.inria.fr\/~maranget\/X\/421\/poly\/automate.html\">finite-state transition automaton<\/a>. The site <a rel=\"noreferrer noopener\" href=\"https:\/\/regexper.com\/\" target=\"_blank\">https:\/\/regexper.com\/<\/a> allows you to visualize the automaton associated with your regex. For example:<\/p>\n\n\n\n<p><strong>[ptk].*[aiou][aiou].?ion$ <\/strong>corresponds to the finite automaton:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"538\" height=\"150\" src=\"http:\/\/www.lexique.org\/wp-content\/uploads\/2019\/04\/exregex.png\" alt=\"\" class=\"wp-image-120\" srcset=\"http:\/\/www.lexique.org\/wp-content\/uploads\/2019\/04\/exregex.png 538w, http:\/\/www.lexique.org\/wp-content\/uploads\/2019\/04\/exregex-300x84.png 300w\" sizes=\"auto, (max-width: 538px) 100vw, 538px\" \/><\/figure><\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Regular expressions, or regex, are &#8220;patterns&#8221; that allow you to search for words with certain properties. Here are some examples of regular expressions: ion: searches for words that contain the string &#8220;ion&#8221; in any position ion$: words ending with &#8220;ion&#8221; ($=end of word) ^anti: searches for all words beginning with &#8220;anti&#8221; (^=beginning of word) ^house$: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":841,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-847","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=847"}],"version-history":[{"count":1,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/847\/revisions"}],"predecessor-version":[{"id":848,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/847\/revisions\/848"}],"up":[{"embeddable":true,"href":"http:\/\/www.lexique.org\/index.php?rest_route=\/wp\/v2\/pages\/841"}],"wp:attachment":[{"href":"http:\/\/www.lexique.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}