View Full Version : Regular Expression to exclude a specific string
dragon6158
02-07-2008, 05:26 PM
I have been trying to come up with a Regular Expression that would exclude the string "Select Router Type". Any help would be appreciated.
Thanks,
Don
To "exclude" something from a string you need a method. And the RegExp method is replace()
myString=myString.replace(/Select Router Type/g,'');
or dynamically:
var reg=new RegExp('Select Router Type','g');
myString=myString.replace(reg,'');
See also:
http://lawrence.ecorp.net/inet/samples/regexp-intro.php
is this what you are looking for?
dragon6158
02-07-2008, 07:30 PM
Unfortunately no, we are using the regular expression as a means of error checking and the reason I am excluding that string is because that is what I am defaulting my variable to so it is automatically an error. Thanks for the advice though.
Don
dragon6158
02-07-2008, 07:45 PM
My supervisor has written some code in a CSS that checks to see if a regular expression returns a true or false condition and changes the color around the variable depending on that condition, ie: if a regular expression is used to check an IP address and the user inputs something that is not a valid IP address, the variable is turned red to tell the user that they messed up.
dragon6158
02-07-2008, 07:50 PM
This is how we use it:
testREG((/Select/),this.value).
This statement tests the value in an input box and returns true or false and turns the variable red or green wherever it is used.
aha... to exclude something from a regular expression evaluation the [^ ... ] characters are to be used. See the link I have posted to you.
dragon6158
02-07-2008, 08:07 PM
Here are the latest ones that I've tried:
testREG((/^"Select Router Type"/),this.value)
testREG((/^Select Router Type/),this.value)
and neither one works.
what is testREG()? A custom function?
dragon6158
02-07-2008, 09:46 PM
Yes it is
dragon6158
02-07-2008, 09:49 PM
This is the testREG function:
function testREG(regexp2,text2) {
if (regexp2.test(text2)) {
return true;
}
return false;}
dragon6158
02-08-2008, 03:56 PM
Kor,
Thanks for your help. My supervisor changed his mind about how he wanted it done which made it a lot simpler.
Don
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.