Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript 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
  #1 (permalink)  
Old August 17th, 2004, 09:48 AM
Authorized User
 
Join Date: Jul 2003
Location: Reading, Berkshire, United Kingdom.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default Regular expression help!!!

<tag><tag>123@#?</tag>

Could anyone please give me a regular expression syntax which will pick up absolutely anything which could appear between <tag> and </tag> please>???

I'm trying to use this, but it picks up the entire string (i.e. the first instance of <tag>, rather than just the "<tag>123@#?</tag>" string...

tag>([\d\D\s\S\w\W]+)</tag

Thanks!!!

__________________
http://www.geocities.com/vbwig/
  #2 (permalink)  
Old August 17th, 2004, 10:24 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Alex,

Try...

Code:
tag>([^<]+)</tag
HTH,

Chris

  #3 (permalink)  
Old August 17th, 2004, 11:01 AM
Authorized User
 
Join Date: Jul 2003
Location: Reading, Berkshire, United Kingdom.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

Hi Chris!

Thanks for the reply! :D Unfortunately, my real life example has some processing instructions in there - the string actually looks more like this:

<tag><tag><tag_2>1</tag_2>2<?instruction1?>3@#?</tag>

I kind of simplified it a bit too much when doing the first post, sorry! What I'm after is to look for everything between the 2 <tag> um, tags within that string.

You're code would have worked great, but for it having the extra <tag_2> and <? instuction tags in there. Thanks again!

  #4 (permalink)  
Old August 18th, 2004, 02:50 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Alex,

In that case you'll need something like:

Code:
<tag>((?:[^<]*|<(?:[^t]|t[^a]|ta[^g]|tag[^\s>]+)[^>]*>)*)</tag>
Bit of a pain to construct for different tags though, so the following function should be of use...

Code:
function GetTagExp(pTagName){
    var temp = "<" + pTagName + ">((?:[^<]*|<(?:";
    for(var i = 0; i < pTagName.length; i++){
        temp += pTagName.substr(0, i);
        temp += "[^" + pTagName.charAt(i) + "]|";
    }
    temp += pTagName + "[^\\s>]+)[^>]*>)*)";
    temp += "</" + pTagName + ">";
    return temp;
}
HTH,

Chris

  #5 (permalink)  
Old August 18th, 2004, 03:44 AM
Authorized User
 
Join Date: Jul 2003
Location: Reading, Berkshire, United Kingdom.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alex_read
Default

That is absolutely fantastic!!!!

Thanks a million Chris, that's great!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression Help Please rstelma ASP.NET 1.0 and 1.1 Professional 0 January 2nd, 2008 07:01 PM
REGULAR EXPRESSION pallone Javascript How-To 0 September 5th, 2006 06:52 AM
regular expression if-then smay Javascript 4 July 5th, 2005 12:10 PM
Regular Expression Help Greg Griffiths Javascript How-To 4 November 12th, 2004 05:33 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.