Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What are delimiters for in Regular Expressions?

I have been gradually amping up my understanding/competency with RegExes. One thing I still have not understood is: what are delimiters for?

For example, I use Regex101 a lot, and I noticed that for every flavour it has a list of delimiters for it on the left side of the regex field (the three vertical dots).

For pcre flavour it has //~/@/;/% etc etc.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

For .NET it has "/""/"""" etc

But what are they for?

All my searches for this topic have turned up the subject of using a regular expression to delimit a string with a substring.

>Solution :

The delimiter’s role is not to affect how the regex is interpreted in terms of pattern matching. Instead, it provides a way to separate the regex pattern from other parts of the code or terminal tool’s interface, ensuring clarity and adhering to the conventions of the environment in which the regex is used.

When you’re using regular expressions within various programming languages or platforms, there are often conventions or syntax requirements that you need to be aware of.

For example in PHP language that use delimiters, often there’s an opportunity to append modifiers right after the closing delimiter. These modifiers can adjust the behaviour of the regex, such as making it case-insensitive.

preg_match('/[a-z]+/i', $string, $matches);

Regex101 provides a selection of delimiters for the flavor you choose because it wants to give you a representation of how you’d write the regex in the actual programming environment for that flavor.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading