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
459 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
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…

773 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