Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which characters can be used as regular expression delimiters?

Tags:

Which characters can be used as delimiters for a Perl regular expression? m/re/, m(re) and måreå all seem to work, but I'd like to know all possibilities.

like image 300
Tim Avatar asked Apr 24 '11 12:04

Tim


People also ask

What are the regex special characters?

Special Regex Characters: These characters have special meaning in regex (to be discussed below): . , + , * , ? , ^ , $ , ( , ) , [ , ] , { , } , | , \ . Escape Sequences (\char): To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ).

Which delimiter is used to remove character meaning in PHP?

Delimiters ¶ Often used delimiters are forward slashes ( / ), hash signs ( # ) and tildes ( ~ ).

Is whitespace a character regex?

\s stands for “whitespace character”. Again, which characters this actually includes, depends on the regex flavor. In all flavors discussed in this tutorial, it includes [ \t\r\n\f]. That is: \s matches a space, a tab, a carriage return, a line feed, or a form feed.

Is slash a special character in regex?

The forward slash character is used to denote the boundaries of the regular expression: ? The backslash character ( \ ) is the escaping character. It can be used to denote an escaped character, a string, literal, or one of the set of supported special characters.


1 Answers

From perlop:

With the m you can use any pair of non-whitespace characters as delimiters.

So anything goes, except whitespace. The full paragraph for this is:

If "/" is the delimiter then the initial m is optional. With the m you can use any pair of non-whitespace characters as delimiters. This is particularly useful for matching path names that contain "/", to avoid LTS (leaning toothpick syndrome). If "?" is the delimiter, then the match-only-once rule of ?PATTERN? applies. If "'" is the delimiter, no interpolation is performed on the PATTERN. When using a character valid in an identifier, whitespace is required after the m.

like image 156
Mat Avatar answered Oct 13 '22 10:10

Mat