Regular expression examples: Difference between revisions

Content deleted Content added
m categ
conventions
Line 2:
 
Despite this variability, and because regular expressions can be difficult to both explain and understand without examples, this article provides a basic description of some of the properties of regular expressions by way of illustration.
 
== Conventions ==
The following conventions are used in the examples.<ref name="clarify000">The character 'm' is not always required to specify a perl match operation. For example, m/[^abc]/ could also be rendered as /[^abc]/. The 'm' is only necessary if the user wishes to specify a match operation without using a forward-slash as the regex [[delimiter]]. Sometimes it is useful to specify an alternate regex delimiter in order to avoid "[[Delimiter#Delimiter_collision|delimiter collision]]". See '[http://perldoc.perl.org/perlre.html perldoc perlre]' for more details.</ref>
 
=~ m// ;; indicates a regex '''match''' operation in perl
=~ s/// ;; indicates a regex '''substitution''' operation in perl
metacharacter(s) ;; the metacharacters column specifies the regex syntax being demonstrated
 
== Examples ==
Line 297 ⟶ 304:
 
== Notes ==
<references />
The character 'm' in the above regular expressions, for example m/[^abc]/, is not required in order for perl to recognize the expression as a 'match' (cf. 'substitute': s/a/b/); /[^abc]/ could just as easily be used without the preceding 'm'. The 'm' operator can be used to alter the delimiting character; for example, m{/} may be used to enhance the legibility of patterns such as /\//. See '[http://perldoc.perl.org/perlre.html perldoc perlre]' for more details.
 
== See also ==