Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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/
Reply With Quote
  #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

Reply With Quote
  #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!

Reply With Quote
  #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

Reply With Quote
  #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!

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:08 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.