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
457 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:NeilT
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 74

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
 
LVL 74

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 74

Expert Comment

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

Author Closing Comment

by:NeilT
ID: 35025472
Excellent, many thanks
Neil
0
 
LVL 74

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now