• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Reg Ex Alter and Replace

Hello All.

I need to change:

<previous art_id="[something]">[something2]</previous>
to
<a href="[something2]">[something2]</a>

However, the first for the first [something2] I need to replace special characters like whitespaces before i rewrite it.  So this wouldn't work:

$content=~s /<previous art_id=\"[a-zA-Z0-9._-]+\">(.*)<\/previous>/<a href=\"$1\">$1<\/a>/gi;

Because the first $1 still has characters that I want to replace for links.

For an actual example:

<previous art_id="insurance">Homeowner's Insurance</previous>
needs to be
<a href="Homeowner&#39;s+Insurance">Homeowner's Insurance</a>

Thanks for the help in advance!  Hope I made everything clear enough.
0
Igiwwa
Asked:
Igiwwa
1 Solution
 
ozoCommented:
$content=~s /<previous art_id="[^"]*">(.*)<\/previous>/<a href="@{[encode($1)]}">$1<\/a>/gi;
sub encode{
  local $_ = shift;
  s/ /+/g;
  s/'/&#39;/g;
  return $_;
}
print $content;
0
 
IgiwwaAuthor Commented:
awesome, thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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