Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: string replacement question

by secret (Beadle)
on Dec 08, 2005 at 09:24 UTC ( [id://515172]=note: print w/replies, xml ) Need Help??


in reply to string replacement question

Hello,

You say :

I want to replace "C:\Program Files\180searchassistant\salmhook.dll" with "C:\Program Files\180searchassistant\salmhook.dll"

But these two string are identical ?!
As i understand it you have a problem with the backslash. It's not a real problem : escape the backslash

# note the use of single quotes $string = 'c:\foo\bar\weird program name.exe' ; # using another regexp separator for readability $string =~ s[foo\\bar][foo\\baz] ; # Or with / as the separator $string =~ s/foo\\bar/foo\\baz/ ;
Well, you can do this a gazillion ways there's no problems with the backslash ...

Now about replacing japanese characters with a regexp, as i understand this will call for unicode regexp. Supersearch will give you some result.

Replies are listed 'Best First'.
Re^2: string replacement question
by ww (Archbishop) on Dec 08, 2005 at 14:35 UTC
    But, pedantically, note the initial phrasing of OP's post DOES appear to specify a replacement:
    my goal is to replace C:\Program Files\180searchassistant\salmhook.dll to a custom file name "C:\japansese characters\japnaese character filename.exe"
    .

    nonetheless, ++ for the portion of your post re the backslash...

    and re OP's problem with multiple instances of "However I can't do the replacement globally because ... there are 2 places that hold filenames. " one might suggest that:

    • if OP knows the replaceable-instance always comes first, a simple regex, applied NON-globally (ie, *WITHOUT* a /g) should do the trick
    • if placement of the replaceable-instance is unknown or variable, my first thought would be to see if some other defining characteristic (context, for example) might be used in the regex
    FWIW....
    ww

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-24 08:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found