Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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
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 (Canon) 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 pondering the Monastery: (5)
As of 2015-10-09 00:15 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (232 votes), past polls