JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 18th, 2013, 02:44 PM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 99 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
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?

Reply With Quote
  #2  
Old February 18th, 2013, 06:59 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,680 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 1 h 55 m 43 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
.test() only tells you whether there was a match. If you need more information then use a different method, like .exec.

Reply With Quote
  #3  
Old February 20th, 2013, 03:01 PM
we5inelgr we5inelgr is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 99 we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level)we5inelgr User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 21 h 59 m 39 sec
Reputation Power: 1
thanks.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > RegExpObject.test(string) How to find which in array was found, then look back/ahead?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap