Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

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 June 9th, 2009, 11:17 PM
mikek12f mikek12f is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 2 mikek12f User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 39 sec
Reputation Power: 0
VBScript regex newbie question ... please help

I am new to VBscript regular expressions and would like to know if it is possible to do the folloiwng using VBScript regular expressions and if so how.

I have a string that has a number of constant substrings within it. I would like to
make sure if all the substrings are present within the string, and if so

a) set a matchfound or no is matchfound variable
b) if no or partial match found, list the Substring entries for which the match failed.

Let us say the string to verify against is

"somestring1 Word1 someotherstring2 word2 someotherstring3 word3 someotherstring4"


if I find that word1, word2, and word3 are found, I would declare match is found. Otherwise I would list the entries for which there was no match found, example "word1" if it was not found.



I would like to avoid using VBScripts "inString".

Can this be done or does vbscripts regular expression can search for one pattern at a time.

Thanks.

This is what I got so far ...

strSearchOn = "xyz Word1 dsew12 word2 err3 word3 dfdfd"

Dim objRegExpr

Set objRegExpr = New regexp

objRegExpr.Global = True
objRegExpr.IgnoreCase = True

objRegExpr.Pattern = ".*\s(word1).*\s(word2).*\s(word3).*"

Dim colMatches

Set colMatches = objRegExpr.Execute(strSearchOn)


Wscript.Echo colMatches.count
msgBox colMatches

Set colMatches = objRegExp.Execute(strTest)


WScript.Echo colMatches

But it does not capture the matching entries.

Reply With Quote
  #2  
Old June 10th, 2009, 01:09 AM
salem's Avatar
salem salem is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2005
Posts: 2,139 salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 1 Month 2 Weeks 1 Day 23 h 22 m 21 sec
Reputation Power: 861
You have to be careful when you use ".*", because that tends to match everything.

Given your example, of trying to capture alternate words, I would suggest something like

Code:
objRegExpr.Pattern = "\w+\s(\w+)\w+\s(\w+)\w+\s(\w+)"

\w+ matches the first word you want to ignore
\s matches a single space
(\w+) matches a word, and captures it for later use.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Reply With Quote
  #3  
Old June 10th, 2009, 07:15 AM
mikek12f mikek12f is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 2 mikek12f User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by salem
You have to be careful when you use ".*", because that tends to match everything.

Given your example, of trying to capture alternate words, I would suggest something like

Code:
objRegExpr.Pattern = "\w+\s(\w+)\w+\s(\w+)\w+\s(\w+)"

\w+ matches the first word you want to ignore
\s matches a single space
(\w+) matches a word, and captures it for later use.


Thanks for your reply Salem. I tried this

strSearchOn = "xyz Word1 dsew12 word2 err3 word3 dfdfd"
Dim objRegExpr
Set objRegExpr = New regexp
objRegExpr.Global = True
objRegExpr.IgnoreCase = True
' objRegExpr.Pattern = ".*\s(word1).*\s(word2).*\s(word3).*"
objRegExpr.Pattern = "\w+\s(\w+)\w+\s(\w+)\w+\s(\w+)"
Dim colMatches
Set colMatches = objRegExpr.Execute(strSearchOn)
Wscript.Echo colMatches.count

msgBox colMatches.count

WScript.Echo colMatches

and it turns up 1 match. however when I try to print the match string I get a type mismatch error on the line '
WScript.Echo colMatches'

What am I doing wrong here?

Tx again

Reply With Quote
  #4  
Old June 10th, 2009, 12:34 PM
salem's Avatar
salem salem is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jun 2005
Posts: 2,139 salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)salem User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 1 Month 2 Weeks 1 Day 23 h 22 m 21 sec
Reputation Power: 861
1. I mucked up the regex

Code:
objRegExpr.Pattern = "\w+\s(\w+)\s(\w+)\s(\w+)"


2. You're trying to print the whole object which is colMatches
> WScript.Echo colMatches
I would have guessed that you need to loop over colMatches.count to print each entry of some kind of array of strings.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > VBScript regex newbie question ... please help


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




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
Stay green...Green IT