Solved

Regular Expression pattern for word search

Posted on 2008-10-16
6
1,298 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

829 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