
February 18th, 2013, 02:44 PM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 99
 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
|
|
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?
|