Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Regular-expressions/Perl/regular-expressions-1.pl
Normal file
8
Task/Regular-expressions/Perl/regular-expressions-1.pl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
$string = "I am a string";
|
||||
if ($string =~ /string$/) {
|
||||
print "Ends with 'string'\n";
|
||||
}
|
||||
|
||||
if ($string !~ /^You/) {
|
||||
print "Does not start with 'You'\n";
|
||||
}
|
||||
3
Task/Regular-expressions/Perl/regular-expressions-2.pl
Normal file
3
Task/Regular-expressions/Perl/regular-expressions-2.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$string = "I am a string";
|
||||
$string =~ s/ a / another /; # makes "I am a string" into "I am another string"
|
||||
print $string;
|
||||
3
Task/Regular-expressions/Perl/regular-expressions-3.pl
Normal file
3
Task/Regular-expressions/Perl/regular-expressions-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$string = "I am a string";
|
||||
$string2 = $string =~ s/ a / another /r; # $string2 == "I am another string", $string is unaltered
|
||||
print $string2;
|
||||
4
Task/Regular-expressions/Perl/regular-expressions-4.pl
Normal file
4
Task/Regular-expressions/Perl/regular-expressions-4.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
$string = "I am a string";
|
||||
if ($string =~ s/\bam\b/was/) { # \b is a word border
|
||||
print "I was able to find and replace 'am' with 'was'\n";
|
||||
}
|
||||
7
Task/Regular-expressions/Perl/regular-expressions-5.pl
Normal file
7
Task/Regular-expressions/Perl/regular-expressions-5.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# add the following just after the last / for additional control
|
||||
# g = globally (match as many as possible)
|
||||
# i = case-insensitive
|
||||
# s = treat all of $string as a single line (in case you have line breaks in the content)
|
||||
# m = multi-line (the expression is run on each line individually)
|
||||
|
||||
$string =~ s/i/u/ig; # would change "I am a string" into "u am a strung"
|
||||
4
Task/Regular-expressions/Perl/regular-expressions-6.pl
Normal file
4
Task/Regular-expressions/Perl/regular-expressions-6.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
$_ = "I like banana milkshake.";
|
||||
if (/banana/) { # The regular expression binding operator is omitted
|
||||
print "Match found\n";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue