[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 352
  • Last Modified:

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,
0
Tolgar
Asked:
Tolgar
  • 4
  • 2
1 Solution
 
käµfm³d 👽Commented:
Try:

$fileLine =~ s#href="(file://///).*?(/20YYMMDD_HHMM)#$1***$2#;

Open in new window

0
 
TolgarAuthor Commented:
@kaufmed: It just replaced href="(file: with ***
0
 
TolgarAuthor Commented:
Any ideas???
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
käµfm³d 👽Commented:
What is your environment? I was testing in Windows with ActiveState Perl, and my test was successful:

Screenshot
0
 
TolgarAuthor Commented:
I tried it both on unix and windows.
0
 
ozoCommented:
What exactly did you try, and how did you try it?
0
 
TolgarAuthor Commented:
I apologize. It works. I made a mistake in overwriting to the file.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now