Solved

Regular Expression pattern for word search

Posted on 2008-10-16
6
1,297 Views
Last Modified: 2012-06-22
I am using VBA in MS Access 2003 referencing "Microsoft VBScript Regular Expressions 5.5"
I want a collection of all the complete words in my search string that contains the pattern "colla".
So what must the Regular Expression search pattern be to return all the words in this string:
strMySeachString = "collaborate collaboratively collastart thecollatest incollalong endincolla COLLAnow"
0
Comment
Question by:vergenoeg
  • 4
6 Comments
 
LVL 5

Accepted Solution

by:
zmo earned 250 total points
ID: 22737251
> strMySeachString = "collaborate collaboratively collastart thecollatest incollalong endincolla COLLAnow"

I don't know any VB, but I do know about regexps.
from what I see, you have the 'colla' substring in all of these strings, so a regexp could be :

[a-zA-Z]*[cC][oO][lL][lL][aA][a-zA-Z]*

([a-zA-Z] can also be \w, depending on your regexp language])
0
 

Author Comment

by:vergenoeg
ID: 22737319
It works great.  Thanks.  What if there are digits in the string as well, like:
strMySeachString = "colla2222 222collastart the222collatest COLLA12345"
0
 

Author Comment

by:vergenoeg
ID: 22737434
So I want all these words to be returned when "colla" is supplied:
strMySeachString = "collaborate collaboratively collastart thecollatest incollalong endincolla COLLAnow colla2222 222collastart the222collatest COLLA12345 "
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:vergenoeg
ID: 22737518
I see your initial solution works for this as well.  Many thanks.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22737532
as zmo noted, use of \w is an option but would match [a-zA-Z0-9_], if the [_] is an issue replace \w below with [a-z0-9]

Set regEx = New RegExp
regEx.Global = True
regEx.IgnoreCase = True
regEx.Pattern = "\w*colla\w*"
Set Matches = regEx.Execute(strMySeachString)
0
 

Author Closing Comment

by:vergenoeg
ID: 31507011
Thanks for your help.  This was my first ever question here, so I hope I did everything right!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question