Wrox Programmer Forums
|
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 11th, 2008, 07:29 AM
Authorized User
 
Join Date: Nov 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default REGEX to get href="#"

Dear All,

I have an href, for example <a href='http://www.google.com'>google</a>, and I need to strip it off to make it unclickable, so I wish for it to be replaced by <a href='#'>google</a>.

Can you suggest me a RegEx pattern to achieve this, since I am not very good with RegEx's.

Thanks

Regards

Johann

 
Old July 24th, 2008, 09:25 AM
Registered User
 
Join Date: Jul 2008
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So you want a regexp that fits something like this:
Code:
<a href="http://www.example.com/example/url.html">
You could try
Code:
<a href=["']*[^>"']+["']*>
the square brackets means any character, the ^ means "negation" and the > and " are the two characters you don't want inside.

http://www.myetymology.com --word etymology website
 
Old July 24th, 2008, 11:46 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

In perl this would work most of the time:

Code:
s/(a href=")[^"](")/$1#$2/g;
So:
Code:
charlie:~$ perl -ne 's/(a href=")[^"]+(")/$1#$2/g;print;'
<a href="GOOGLE.COM">google</a> <a href="http://charlieharvey.org.uk">my homepage</a>
<a href="#">google</a> <a href="#">my homepage</a>
charlie:~$
--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8, href and HRef (p. 285) roman BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 June 16th, 2008 10:40 AM
Href in a string seran128 Classic ASP Professional 1 April 14th, 2006 11:05 PM
href darkhalf Javascript 2 November 20th, 2005 10:59 AM
Urgent please HREF mikedeepak HTML Code Clinic 2 September 26th, 2005 08:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.