Solved

after some regex that I can run in textpad or similar to remove all <a href tage from text

Posted on 2011-03-02
8
462 Views
Last Modified: 2012-05-11
Hi

I have 150 pages that I need to remove all the links from (APART FROM ANCHOR TAGS <a name...) so I intend to open them in textpad and clear via some kind of regex

I want to keep the text that was in the links though so for example

<a href="test/test.htm">this is a test</a> would become simply this is a test
<a name="test"></a> would remain intact.

Points for full working regex please
Regards
Neil
0
Comment
Question by:Neil Thompson
[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
8 Comments
 
LVL 16

Expert Comment

by:sjklein42
ID: 35018087
Something like this should do it, as long as the "href" is always the first thing after the "<a":

s/\<a href\=[^\>]*\>//ig

Open in new window

0
 
LVL 8

Expert Comment

by:crysallus
ID: 35018170
I don't have textpad to test what will work with that, but in regexr this seems to work:

(?=<a[^>]+href)<a[^<>]*?>(.*?)</a>

Open in new window

0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35018429
Tested in TextPad:

Find
(<a [^>]*?)href=[^ >]+([^>]*>)

Open in new window


Replace
\1\2

Open in new window


You may want to follow that up with this to remove extra spaces left from the previous replace:

Find
(<a)[[:space:]]{2,}|(<a [^>]*)[[:space:]]{2,}

Open in new window


Replace
\1 

Open in new window


You may have to execute the latter a couple of times in succession.
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!

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35018460
P.S.

I run TP with POSIX regular expression syntax enabled. If the above doesn't work for you, you can enable this option by going to Configure--Preferences--Editor--Use POSIX regular expression syntax.
untitled.PNG
0
 
LVL 16

Expert Comment

by:sjklein42
ID: 35018464
My attempt wasn't too good.

kaufmed:  does your's strip the </a> tags?  (mine didn't)
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35018487
Negative.
0
 
LVL 3

Author Closing Comment

by:Neil Thompson
ID: 35025472
Excellent, many thanks
Neil
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35025992
NP. Glad to help    = )
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

696 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