Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: difference in regex

by haukex (Archbishop)
on May 29, 2018 at 14:03 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1215373]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-03-28 18:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found