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

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.

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
i need to change the "install_temp" or "install_patch" folder to "install" like below.
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

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' +;

    Output:

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://997230]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-11-29 01:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (200 votes), past polls