Solved

adding stuff in string.....

Posted on 2000-04-15
7
224 Views
Last Modified: 2010-08-05
hi all

i have this string :
<li><a href="/anydir/anylink.html">any text for the link</a>

and i want to get this:
<li><a href="http://www.myserver.com/anydir/anylink.html">any text for the link</a>

do someone have any idea..???

tanks
popy
0
Comment
Question by:popy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:monas
ID: 2719017
$x = '<li><a href="/anydir/anylink.html">any text for the link</a>';

$x =~ s#(<a href=")(.*)#$1.'http://www.myserver.com/'.$2/ei;

print $x;
0
 
LVL 3

Expert Comment

by:monas
ID: 2719031
oops

$x = '<li><a href="/anydir/anylink.html">any text for the link</a>';

$x =~ s#(<a href=")(.*)#$1.'http://www.myserver.com/'.$2#ei;

print $x;
0
 

Author Comment

by:popy
ID: 2719051
Adjusted points from 100 to 150
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!

 

Author Comment

by:popy
ID: 2719052
ok, thanks, but now subquestion, this line appear somewhere in the text, i reading text file, then i need to verifing if the line having this tag...
any sugestion...?

popy
0
 
LVL 84

Expert Comment

by:ozo
ID: 2719061
There's really no need for the (.*) .$2 and /e
0
 

Accepted Solution

by:
nmoldav earned 150 total points
ID: 2719067
If you're reading a file, then it should work as follows:

while (<FILE>) {
      if (m!<A\s+HREF="([^"]+"!i) {
            my $link = $1;
            s!HREF="$link"!HREF="http://www.myserver.com/$link"!i;
      }
}

# The if checks whether the pattern is present in the current line and the replace operator adds the server name to the link.
0
 
LVL 3

Expert Comment

by:monas
ID: 2719068
while($x = <FILE>){
  $num = ($x =~ s#(<a href=")#$1.'http://www.myserver.com/'#gei);
  # number of occurences is in $num;
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question