Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

How to match a string in Perl?

How can I capture Report_20120815_1543.html in the given string below?

See Report_20120815_1543.html for details in /dir1/dir2/dir3/dir4 directory.

Open in new window

0
Tolgar
Asked:
Tolgar
  • 6
  • 3
1 Solution
 
TolgarAuthor Commented:
One addition to the initial question:

How can I get this output from the given string:

/dir1/dir2/dir3/dir4/Report_20120815_1543.html

Open in new window



Which means i need to capture the following in addition to the file name:

/dir1/dir2/dir3/dir4

and then concatenate them.

Thanks,
0
 
ozoCommented:
$_='See Report_20120815_1543.html for details in /dir1/dir2/dir3/dir4 directory.';
print "$2/$1" if /See\s+(\S+).*\s(\S+)\s+directory/;
0
 
TolgarAuthor Commented:
Which part of the code captures the html file name?

I think I just need the file name.

Sorry for confusion.

Thanks,
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
TolgarAuthor Commented:
I want to assign the html file name to a variable.
0
 
ozoCommented:
($filename) = /See\s+(\S+)/;
0
 
TolgarAuthor Commented:
should it be something like this if $str is my string?

($filename) = $str = /See\s+(\S+)/;

Open in new window

0
 
ozoCommented:
$str='See Report_20120815_1543.html for details in /dir1/dir2/dir3/dir4 directory.';
($filename) = $str =~ /See\s+(\S+)/;
0
 
TolgarAuthor Commented:
@Ozo: If the string is as the following, how can I can extract 20120815_1543_Report.html from this string?


See 20120815_1543_Report.html for details in /dir1/dir2/dir3/dir4 directory.

Open in new window


Thanks,
0
 
TolgarAuthor Commented:
@Ozo: Can you please take a look at this question?

ID27832004

http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_27832004.html

Thanks,
0

Featured Post

Technology Partners: 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!

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now