Solved

Regular Expression pattern for word search

Posted on 2008-10-16
6
1,295 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
Comment Utility
> 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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

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

Expert Comment

by:ddrudik
Comment Utility
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
Comment Utility
Thanks for your help.  This was my first ever question here, so I hope I did everything right!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now