Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: difference in regex

by haukex (Chancellor)
on May 29, 2018 at 14:03 UTC ( #1215373=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $x = "foobar"=~/[aeiou]/;  # => $x is true
    my $y = "foobar"=~/[xyz]/;    # => $y is false
    
  2. or download this
    my $str = "foobar";
    my $x = $str=~/[aeiou]/g;
    ...
    # matches "a"        => $x is true,  pos($str) is 5
    $x = $str=~/[aeiou]/g;
    # no more matches    => $x is false, pos($str) is undef
    
  3. or download this
    my ($x) = "foobar"=~/[aeiou]/;  # => $x is 1
    
  4. or download this
    my ($x,$y,$z) = "foobar"=~/[aeiou]/g;
    # => $x is "o", $y is "o", $z is "a"
    
  5. or download this
    my ($x,$y) = "foobar"=~/([aeiou])(.)/;
    # => $x is "o", $y is "o"
    
  6. or download this
    my ($w,$x,$y,$z) = "foobar"=~/([aeiou])(.)/g;
    # => $w is "o", $x is "o", $y is "a", $z is "r"
    
  7. or download this
    my $x = "foobar";
    my $y = $x=~s/[aeiou]/x/g;  # => $y is 3
    
  8. or download this
    my $x = "foobar"=~s/[aeiou]/x/gr;
    # => $x is "fxxbxr"
    
  9. or download this
    my ($value) = $row =~ /.*,(.*)/;
    # and
    $row =~ s/,[^,]*$//;
    
  10. or download this
    use Regexp::Common qw/number/;
    
    ...
    
    matched <15>
    row is now <a,b,c,d>
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1215373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2020-01-23 21:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?