Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts

    Regular Expression to exclude a specific string

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    To "exclude" something from a string you need a method. And the RegExp method is replace()
    Code:
    myString=myString.replace(/Select Router Type/g,'');
    or dynamically:
    Code:
    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?
    Last edited by Kor; 02-07-2008 at 06:29 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    dragon6158 (02-07-2008)

  • #3
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    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

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Can you detail?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    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.

  • #6
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    aha... to exclude something from a regular expression evaluation the [^ ... ] characters are to be used. See the link I have posted to you.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    dragon6158 (02-08-2008)

  • #8
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    what is testREG()? A custom function?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Yes it is

  • #11
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    This is the testREG function:

    Code:
    function testREG(regexp2,text2) {
    	if (regexp2.test(text2)) {
    		return true;
    	}
    	return false;}

  • #12
    New Coder
    Join Date
    Jan 2008
    Posts
    93
    Thanks
    30
    Thanked 0 Times in 0 Posts
    Kor,
    Thanks for your help. My supervisor changed his mind about how he wanted it done which made it a lot simpler.

    Don


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •