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

x
?
Solved

adding stuff in string.....

Posted on 2000-04-15
7
Medium Priority
?
239 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
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
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!

 

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 85

Expert Comment

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

Accepted Solution

by:
nmoldav earned 600 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

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.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Six Sigma Control Plans
Suggested Courses

864 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