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 February 1st, 2006, 12:44 AM
Registered User
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default related to regular expression

I would like to know regular expression(s):

    1. to find all the occurences of <img> tags (in HTML text)
          that are enclosed within <a> tags like <a><img /></a>

    2. to find all the occurences of [b]<img> tags (in HTML text)
          that are not enclosed within <a> tags

Old October 27th, 2006, 09:40 AM
Friend of Wrox
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts

I'd probably reccommend using a proper html parser. If thats' not practical you'd want something like (this is in perl):

while(<>) {
  print "Image found $1" if (/(<img[^>]+>)/);
  print "Image within 'a' tag: $1" if (/<a[^>]+>(<img[^>]+>)<\/a>/);
This won't work on multi-line 'a' tags and so on, but it'll get you started.

Don't Stand on your head - you'll get footprints in your hair

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression balajinrs Visual Studio 2005 0 July 24th, 2008 02:11 AM
Regular Expression NewToXSL ASP.NET 1.0 and 1.1 Basics 1 June 13th, 2006 02:52 PM
regular expression if-then smay Javascript 4 July 5th, 2005 12:10 PM
Regular Expression Help anshul PHP How-To 4 December 8th, 2004 05:19 AM
Regular Expression Help Hadware .NET Web Services 3 November 4th, 2003 10:51 AM

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