Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 475
  • Last Modified:

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

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
Neil Thompson
Asked:
Neil Thompson
1 Solution
 
sjklein42Commented:
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
 
crysallusCommented:
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
 
käµfm³d 👽Commented:
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
käµfm³d 👽Commented:
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
 
sjklein42Commented:
My attempt wasn't too good.

kaufmed:  does your's strip the </a> tags?  (mine didn't)
0
 
käµfm³d 👽Commented:
Negative.
0
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Excellent, many thanks
Neil
0
 
käµfm³d 👽Commented:
NP. Glad to help    = )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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