#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3

    Question RegExpObject.test(string) How to find which in array was found, then look back/ahead?


    Hi all,

    I've got a textarea input box that I'm checking for various strings indicated below.
    Code:
    var strFindWebSites=["www", "w w w", "http", "h t t p", "href", "h r e f", ".com", "dot com", ".net", "dot net"];
        var searchExp = new RegExp(strFindWebSites.join("|"),"gim");
    
        if (searchExp.test(theForm.theTextArea.value)) {
    
    ...
    How do I determine which of the strings the .test method found?

    I need to do some further validating of what was found, such as string length to determine if what was found was a "whole word" or if what was found was a part or portion of another string.

    Ex.

    Someone enters "Peridot common" into the textarea.

    I don't want to capture that, but the above code will because it found "dot com"

    If I could find out what the .test method found, I could go backwards, or forwards in the string that it found and check to see if what was found is a "whole" word only, or a part of another word(s).

    Ideas?
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    .test() only tells you whether there was a match. If you need more information then use a different method, like .exec.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    thanks.

IMN logo majestic logo threadwatch logo seochat tools logo