Hi all,
This regular expression stuff does my head in. In theory I can SO understand it, but I seem to run into problems every time I try and do something even slightly complex with it.
So - I've written a little ASP app (in javascript) to take a whole bunch of feedback information out of a database (filled in by delegates of a conference) and have it displayed in a meaningful way on screen. Most of the responses were yes/no or good/bad etc, but there were some free text fields as well. I wanted to be able to print these out, but filter out non-useful comments like 'NA' or 'no comment' etc.
Before we get into the code, here's the page:
Take a look at Q16 + Q17 at the end.
What I did was to take every text entry for a particular question and run it through a function that would test against an array of possible responses I didn't want to include. Here's the function call:
And this is the function killEntry() I wrote:
As you can see I'm attempting to use the test method to copmare the two strings (making sure to include word boundaries as well.) However, it's not picking up the matches at all. The ResponseWrite in there is to check the values as we go along, but testedIt never comes back as true, even when it blatantly is. For example, here's an excerpt from the list of results I get back:
As you can see from line 0 and line 2, we should be getting true returned as the pattern does match the string, but it doesn't.
Can anybody spot what I'm doing wrong? Try as I might, I just can't see to get it to match.
Thanks guys!
Pix
This regular expression stuff does my head in. In theory I can SO understand it, but I seem to run into problems every time I try and do something even slightly complex with it.
So - I've written a little ASP app (in javascript) to take a whole bunch of feedback information out of a database (filled in by delegates of a conference) and have it displayed in a meaningful way on screen. Most of the responses were yes/no or good/bad etc, but there were some free text fields as well. I wanted to be able to print these out, but filter out non-useful comments like 'NA' or 'no comment' etc.
Before we get into the code, here's the page:
Take a look at Q16 + Q17 at the end.
What I did was to take every text entry for a particular question and run it through a function that would test against an array of possible responses I didn't want to include. Here's the function call:
Code:
while (!recSet.EOF) {
//if dbase value not equal to bad responses then print it
if ([B][COLOR=red]killEntry(recSet(valueToPrint))==false[/color][/B]) {
outputString += "<div class='comments'>";
outputString += recSet(valueToPrint);
outputString += "</div>";
}
recSet.MoveNext;
}
And this is the function killEntry() I wrote:
Code:
function killEntry(valueToTest) {
var killValues = new Array('NA','no comment on sheet','NA','Na','no response','undefined');
var testedIt = new Boolean;
for(i=0; i<killValues.length; i++) {
[b][COLOR=red]re = new RegExp("^\b"+killValues[i]+"\b$");
testedIt = re.test(valueToTest)[/color red][/b]
if (testedIt==true)
{ return true;
break; }
//Response.Write(i+" "+re+" = "+valueToTest+" = "+testedIt+"<br/>");
}
return false;
}
As you can see I'm attempting to use the test method to copmare the two strings (making sure to include word boundaries as well.) However, it's not picking up the matches at all. The ResponseWrite in there is to check the values as we go along, but testedIt never comes back as true, even when it blatantly is. For example, here's an excerpt from the list of results I get back:
Code:
...
0 /^NA$/ = NA = false
1 /^no comment on sheet$/ = NA = false
2 /^NA$/ = NA = false
3 /^Na$/ = NA = false
4 /^no response$/ = NA = false
5 /^undefined$/ = NA = false
...
As you can see from line 0 and line 2, we should be getting true returned as the pattern does match the string, but it doesn't.
Can anybody spot what I'm doing wrong? Try as I might, I just can't see to get it to match.
Thanks guys!
Pix