Solved

Regular Expression pattern for word search

Posted on 2008-10-16
6
1,300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

717 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