homepage Welcome to WebmasterWorld Guest from 54.166.173.147
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Regex Question
Javascript, but you guys know regex
Greven




msg:3811007
 5:35 am on Dec 19, 2008 (gmt 0)

This is a copy of post in the javascript forum. I haven't hear anything yet, so figured I'd try with the people that know regular expressions best.

I have a string that I'm matching on, and using the results to generate a custom error message from the one provided. I have a group that should match on values inside a repeating non-matching group. Code as follows:

String to search:

Element '{http://example.com/dev}emailCredit' is unexpected according to content model of parent element '{http://example.com/dev}promotion'.
Expecting: {http://example.com/dev}programmingCredit, {http://example.com/dev}cfppCredit.

Regular Expression:

/^Element '.*' is unexpected according to content model of parent element '.*'.\s*Expecting:(?: {[\w:\/\-]*}(\w*)[,]?)+\w*\.\s*$/

Code executing above

var reqReg = new RegExp(/^Element '.*' is unexpected according to content model of parent element '.*'.\s*Expecting:(?: {[\w:\/\-]*}(\w*)[,]?)+\w*\.\s*$/);
var values = reqReg.exec(exmpleString)//String listed as String to search
errorContainer.appendChild(document.createTextNode(values));

What I would expect to get back as text inside of errorContainer would be:

Element '{http://example.com/dev}emailCredit' is unexpected according to content model of parent element '{http://example.com/dev}promotion'.
Expecting: {http://example.com/dev}programmingCredit, {http://example.com/dev}cfppCredit.
,programmingCredit,cfppCredit

But what I am getting:

Element '{http://example.com/dev}emailCredit' is unexpected according to content model of parent element '{http://example.com/dev}promotion'.
Expecting: {http://example.com/dev}programmingCredit, {http://example.com/dev}cfppCredit.
,cfppCredit

So my question is: Should it not catch on all the nested groups and return each one? It appears that it's only returning the last one.

 

janharders




msg:3812254
 1:04 pm on Dec 21, 2008 (gmt 0)

I'm not completely sure I understand what you're trying to accomplish. Sure enough, I'm not a regexp wizard, but I guess that it happens because you only have one group that will hold the values. You'd have to iterate over the results, which won't work because you're using nested groups, so all are matched.
I'd match the Expecting-part and apply another regexp on that part matching the sub-parts. Oh, and you should probably escape the { in your regexp.

krugs




msg:3812322
 4:33 pm on Dec 21, 2008 (gmt 0)

To me the regexp looks like it should not match anything unless \w is different in javascript than it is in perl. In perl there is no dot (.) in the \w character class so domain names will not be matched:

example.com

maybe it should be:

[\w.:\/-]

note that in perl the order of the characters inside the square brackets is ignored and a dot does not need escaping.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
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