From perlop
:
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.
So I can pick up any letter as a delimiter. Eventually this regex should be fine:
stoutest
That can be rewritten
s/ou/es/
However it does not seems to work in Perl. Why?
$ perl -e '$_ = qw/ou/; stoutest; print'
ou
The JavaScript exception "invalid regular expression flag" occurs when the flags in a regular expression contain any flag that is not one of: g , i , m , s , u , y or d . It may also be raised if the expression contains more than one instance of a valid flag.
What is RegEx Validation (Regular Expression)? RegEx validation is essentially a syntax check which makes it possible to see whether an email address is spelled correctly, has no spaces, commas, and all the @s, dots and domain extensions are in the right place.
When Not to Use Regex. Regular expressions can be a good tool, but if you try apply them to every situation, you'll be in for a world of hurt and confusion down the line. Using them is essentially like injecting a small programming language into another programming language.
Regular expressions are particularly useful for defining filters. Regular expressions contain a series of characters that define a pattern of text to be matched—to make a filter more specialized, or general. For example, the regular expression ^AL[.]* searches for all items beginning with AL.
Because Perl can't pick out the operator s
perldoc perlop
says this
Any non-whitespace delimiter may replace the slashes. Add space after the s when using a character allowed in identifiers.
This program works fine
my $s = 'bout';
$s =~ s toutest;
say $s;
best
Because stoutest
, or any other string of alphanumeric characters, is a single token in the eyes of the Perl parser. Otherwise we couldn't use any barewords that begin with s
(or m
, or q
, or y
).
This works, though
$_ = "ou";
s toutest;
print
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With