Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regex: Changing $1

by space_monk (Chaplain)
on Sep 04, 2013 at 14:30 UTC ( [id://1052355]=note: print w/replies, xml ) Need Help??


in reply to Regex: Changing $1

Try
open (FH,"test.test") or die; while(<FH>) { if ($_ =~ /"(.+?)"/) { print "Matched: $1\n"; s/$1/New string/; } print; }
P.S. You can make a one liner out of this
If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Replies are listed 'Best First'.
Re^2: Regex: Changing $1
by hdb (Monsignor) on Sep 04, 2013 at 14:39 UTC

    Is problematic if $1 also matches outside of the quotes, e.g. test "test".

Re^2: Regex: Changing $1
by choroba (Cardinal) on Sep 04, 2013 at 14:36 UTC
    Only works if $1 does not contain any special characters. Prepend \Q to "quote" all the special characters in $1.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2025-11-16 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.