homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Regular Expressions in Javascript
Hungover and can't cope with it...

 10:37 am on Jan 16, 2002 (gmt 0)

I am a little hungover this morning and my bruised brain isn't coping well... I need a function that can take a string of XML and update a specified node's value that is a member of specified parent node (identified by one of it's siblings). I got so far:

var re;

var parentnode = "buildset"
var newnode = "number"
var newvalue = "30"
var wherenode = "setobject"
var wherevalue = "SetPerson"

var sWhereNode = "<" + wherenode + ">" + wherevalue + "<\\/" + wherenode + ">";
var openParentNode = "<" + parentnode + ">";
var endParentNode = "<\\/" + parentnode + ">";
var openNewNode = "<" + newnode + ">";
var endNewNode = "<\\/" + newnode + ">";

var normString = "(" + openParentNode + ".*" + sWhereNode + ".*" + openNewNode + ").*(" + endNewNode + ".*" + endParentNode + ")"

re = new RegExp(normString);

//You'll need to unwrap this long string
xml = "<buildsets><setsname>View</setsname><buildset>

xml = xml.replace(re, "$1" + newvalue + "$2");



In the example given above I want to change the <number> node (newnode) to 30 (newvalue) where the parent or group node is <buildset> (parentnode). However I only want to update the <number> node in the <buildset> group that has a node called <setobject> with a value of SetPerson. Follow??

The match comes out but it always inserts the update in the last parentnode group. Grrr! At present it's OK to assume that the newnode appears after the wherenode in the parent group.

Please help :(



 11:45 am on Jan 16, 2002 (gmt 0)

OK, simpler question...

In RegExp how can I test that a string does NOT contain a string without switching the boolean after output?


testString = "thatstringdoesntappearhere"

I would want the test to return true if the string DIDN'T contain, say, "josh".

I've tried

re = /(josh){0}/
re = /[^(josh)]/

each without success.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved