Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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...

Comment on Need help to substitute
Select or Download Code
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 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 Athanasius (Monsignor) 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-09-18 08:49 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (109 votes), past polls