Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Need help to substitute

by Divakar (Sexton)
on Oct 04, 2012 at 13:21 UTC ( #997230=perlquestion: print w/replies, xml ) Need Help??
Divakar has asked for the wisdom of the Perl Monks concerning the following question:

Hi Folks,

My variable contains below value which has "install_temp" or "install_patch" folder.

i need to change the "install_temp" or "install_patch" folder to "install" like below.

i am not sure how can i make this using regular expressions?

Thank you...

Replies are listed 'Best First'.
Re: Need help to substitute
by 2teez (Priest) on Oct 04, 2012 at 13:40 UTC

    like so:

    use warnings; use strict; while (<DATA>) { chomp; print "before change: ", $_, $/; s/(.+?)install.+?\\(.*?)/$1install\\$2/; print "After change: ", $_, $/; } __DATA__ D:\ostore_7.3.0_tfix_bld\install_temp\OStore\bin\os_coll.adb D:\ostore_7.3.0_tfix_bld\install_patch\osji\lib\osjiload.ldb

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: Need help to substitute
by nemesdani (Friar) on Oct 04, 2012 at 13:29 UTC
    You need to escape the \-s. After that

    =~ s/(install_temp|install_patch)/install/ should work. Or am I missing something?

    I'm too lazy to be proud of being impatient.
Re: Need help to substitute
by Athanasius (Chancellor) on Oct 04, 2012 at 14:49 UTC

    A variation on the theme, using Look-Around Assertions:

    #! perl use v5.12; say s! ( ?<= \\ install ) _ .+? ( ?= \\ ) !!rx for 'D:\ostore_7.3.0_tfix_bld\install_temp\OStore\bin\os_coll.adb' +, 'D:\ostore_7.3.0_tfix_bld\install_patch\osji\lib\osjiload.ldb' +;


    D:\ostore_7.3.0_tfix_bld\install\OStore\bin\os_coll.adb D:\ostore_7.3.0_tfix_bld\install\osji\lib\osjiload.ldb

    Hope that helps,

    Athanasius <°(((><contra mundum

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997230]
Approved by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2017-02-26 09:01 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (372 votes). Check out past polls.