Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expression help

Status
Not open for further replies.

axman505

Technical User
Jun 20, 2001
489
0
0
US
Hello,

I am trying to match the follwoign with a perl regular expression, but I have been unsuccessful. Here is the string:

<a href="some link" onclick="stuff">link name</a> or <a href="some link" onclick="stuff">link name</a></p><h2><br>

Any suggestions?

My final goal is to replace this with the correct info
 
axman hi,

Which part(s) do you want to replace?

Mike

"Deliver me from the bane of civilised life; teddy bear envy."

Want to get great answers to your Tek-Tips questions? Have a look at faq219-2884

 
i need to preserve where the link points, and replace everything else.
 
Is everything except 'some link', 'link name' and 'stuff' always going to be part of the string to replace? And is the ' or <a' alternative link always part of it? If so, I think the following:

s/<a href="([^"]*)"[^>]*>[^<]*<\/a> or <a href="([^"]*)"[^>]*>[^<]*<\/a><\/p><h2><br>/$1, $2/

should work.

Dom
 
Code:
#!/usr/bin/perl

@links = ('<a href="some link" onclick="stuff">link name</a>',
          '<a href="some link" onclick="stuff">link name</a></p><h2><br>');
           
foreach (@links) {
  m|([^"]+)"([^"]+)"([^"]+)"([^"]+)"([^"]+)|;
  print "part 1: $1\n";
  print "part 2: $2\n";
  print "part 3: $3\n";
  print "part 4: $4\n";
  print "part 5: $5\n\n";

}

this gives output:-

Code:
[red]part 1: <a href=
part 2: some link
part 3:  onclick=
part 4: stuff
part 5: >link name</a>

part 1: <a href=
part 2: some link
part 3:  onclick=
part 4: stuff
part 5: >link name</a></p><h2><br>[/red]

now it's easy to alter...


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top