meshesnot has asked for the wisdom of the Perl Monks concerning the following question:

I'm using InstallAnywhere to do some pattern matching and replacing in the specified file. There is only one line in this file I want to modify. It looks like this:

bla.bla.bla = SomeWindows/Path With/Spaces In/It
I want to change it to this:
bla.bla.bla = SomeWindows/Path\ With/Spaces\ In/It
The challenge is InstallAnywhere gives me two places to type, one says "Search For" and one says "Replace With". So if I only had one space to replace, and I didn't need the /g, I think it would look something like this:

Search For:

^(bla.bla.bla\s=\s)([\S]+)(\s)([\S]+)$
Replace With:
$1$2\\$3$4
Even this isn't working (it is in a test perl program, but not in IA, so I will call them about that tomorrow). But even if I get this to work, it won't help me if there are two spaces in the path. I need a global search and replace. So, I was wondering if I need to venture off into uncharted territory and use the cloistered pattern modifiers, but I have to admit, I am lost when I read that chapter in the Programming Perl. Any ideas are greatly appreciated.

meshesnot

Replies are listed 'Best First'.
Re: Pattern Match / Replace without s/
by tachyon (Chancellor) on Apr 14, 2003 at 00:45 UTC

    Sonething simple like this does the job:

    my $find = quotemeta 'bla.bla.bla'; while(<DATA>) { if ( m/($find\s*=\s*)(.+)/s ) { my $begin = $1; my $change = $2; $change =~ s/ /\\ /g; print $begin.$change; } else { print; } } __DATA__ # don't change me bla.bla.bla = c:/Some Windows/Path With/Spaces In/It # don't change me # don't change me # don't change me

    Which will print:

    # don't change me bla.bla.bla = c:/Some\ Windows/Path\ With/Spaces\ In/It # don't change me # don't change me # don't change me

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Pattern Match / Replace without s/
by tall_man (Parson) on Apr 14, 2003 at 04:10 UTC
    I doubt that InstallAnywhere will give you the full power of perl regular expressions. Since you know the exact line you want, why not just replace it literally?
    Search For: bla.bla.bla = SomeWindows/Path With/Spaces In/It Replace With: bla.bla.bla = SomeWindows/Path\ With/Spaces\ In/It
    You might need to double the "\" characters.
Re: Pattern Match / Replace without s/
by Oberon (Monk) on Apr 14, 2003 at 19:19 UTC
    > I'm using InstallAnywhere to do some pattern matching and replacing in the specified file. ...

    I'm not sure I understand. Is InstallAnywhere using Perl underneath to implement this search and replace? I don't really know anything about this product, but from a quick web search I'm guessing not.

    So, if it's Java underneath, as I suspect it is, I don't know that Perl folks can necessarily help you. If it were full-on Perl underneath, you might try taking it in three steps:

    SEARCH: / (?=.*=/ REPLACE: /%space%/ SEARCH: / / REPLACE: /\\ / SEARCH: /%space%/ REPLACE: / /

    (without the slashes, natch). That wouldn't be quite perfect, I fear, because I think it would backslash the space immediately following the =. But it'd be close.

    But I think the conversation is moot because I don't think it's really a Perl question.

Re: Pattern Match / Replace without s/
by meshesnot (Novice) on Apr 14, 2003 at 20:32 UTC
    Well, as it turns out, InstallAnywhere doesn't have a regular expression engine in the basement. It is a java based product, and the "Search For" and "Replace With" fields can only accept literal strings, as I'm told from technical support this morning. Unfortunately, the documentation leads you to believe it carries the power of regular expressions. :-(.

    So ... I'm going to write some java code to accomplish this task.

    Sorry to bother you all ... and thanks to those of you who responded! :-).

    -meshesnot