Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to make a string substitution in a very long string in Perl?

Hi,
I have a very long string and in that string I have the following pattern in most places.


href="file://///dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/REPORT_Unix/20YYMMDD_HHMM_ReportDetails.html#/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/@dir12/@13/file1.cpp

Open in new window



I'd like to convert this types of patterns to the following form:
href="file://///***/20YYMMDD_HHMM_ReportDetails.html#/dir1/dir2/dir3/dir4/dir5/dir6/dir7/dir8/dir9/dir10/dir11/@dir12/@13/file1.cpp

Open in new window


How can I do it?

I tried the following but it did not work:

$fileLine =~ s{ href=\w+_20 }{\ /20};

Open in new window


The directory names (dir1, dir2, dir3) may change so the rule should be something like this?

Replace between href="file:///// and 20YYMMDD_HHMM with ***


Thanks,
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

@kaufmed: It just replaced href="(file: with ***
Avatar of Tolgar

ASKER

Any ideas???
What is your environment? I was testing in Windows with ActiveState Perl, and my test was successful:

User generated image
Avatar of Tolgar

ASKER

I tried it both on unix and windows.
What exactly did you try, and how did you try it?
Avatar of Tolgar

ASKER

I apologize. It works. I made a mistake in overwriting to the file.