⊗ppPmRgMdRC 263 of 447 menu

Comments in Regex in PHP

The modifier x allows placing arbitrary spaces and line breaks in the regex. Moreover, the hash symbol becomes a single-line comment symbol (accordingly, the delimiters will have to be replaced with others).

Let's look at an example. Suppose we have the following regex:

<?php preg_replace('#[a-z]+@[0-9]+#', '!', 'aaa@333'); ?>

Let's use the modifier x and add explanatory comments for each part of our regex:

<?php preg_replace('~ [a-z]+ # letters @ # at symbol [0-9]+ # digits ~x', '!', 'aaa@333'); ?>
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline