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

Re: You won't believe what this regular expression does!

by LanX (Sage)
on Feb 25, 2021 at 13:01 UTC ( #11128780=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
      DB<32> p "hello" =~ s/o*$/O/gr;
    hellOO
      DB<33> $_="hello"; s/o*$/O/g; print       # for older Perls
    hellOO
      DB<34>
    
  2. or download this
      DB<41> $_="hello"; say pos,"($1)" while m/(o*$)/g;   # pos doesn't c
    +hange
    5(o)
    ...
    
      DB<42> p "hello" =~ s/x*$/O/gr;                      # empty match (
    +no x)
     helloO
    
  3. or download this
      DB<44> p "hello\nfoo" =~ s/o*\n/O/gmr;
    hellOfoo
      DB<45> p "hello\nfoo\n" =~ s/o*\n/O/gmr;    # added \n at the end of
    + input
    hellOfO
      DB<46>
    
  4. or download this
      DB<59> p "12345" =~ s/x*/ /gmr;
     1 2 3 4 5
      DB<60>
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-05-23 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?