Thursday, October 11, 2007

Using regex for matching multiple words anywhere in the sentence

This blog post is to save time for those developers who want to use Regular Expressions to determine whether ALL of the multiple words are located anywhere in the input string. It took me several hours to make it work right for 3 sets with 3 alternative words in each set. Google was not to much help, only a couple of pages contained useful examples.

It began with me implementing regex (regular expressions) matching mechanism for our Sametime Bot to make a more flexible pattern-matching solution than current wildcard matching. So that instead of simply specifying *helpdesk* to match all incoming questions where word "helpdesk" is present, with regex it is possible to fine-tune the match and handle "what is phone number to helpdesk?" incoming question and "How can I contact helpdesk on weekends" question differently. Matching capabilities of regex are amazing, there are very little operations you can't do with it.

Pattern "any one word is enough":
helpdesk|assistance|support

Matches for: Can I get some assistance? How can I contact support? Does helpdesk have an email address?
Not matches for: What's the time? Can you assist me?

-------------------------------------

Pattern "all words must be present":
^(?=.*?(phone|fone|call|contact))(?=.*?(help|assistance|support)).*$

Matches for: What is the phone number to helpdesk? Can I call to support department from my cell phone? How can I contact helpdesk?
Not matches for: I need help! I want to call my mom. My phone doesn't work. Charlie, Charlie, this is Bravo, send more air support!

-------------------------------------

Pattern "all words must be present, but NOT that one":
^(?=.*?(phone|fone|call|contact))(?=.*?(help|assistance|support))((?!weekend|night).)*$

Matches for: I want to come in contact with support now. I need phone assistance to install ABC software today.
Not matches for: What number can i call on weekends to get help with this tool? What phone number can I call to contact helpdesk at night?

-------------------------------------


With a little help from blog post on lekkimworld, I created this LotusScript testing module so the creator of the pattern can test the pattern functionality by providing a text string which is matched to the pre-defined regex expression. The result of the test is either Match or Not match.

Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set doc=uidoc.Document
Dim regexp As Variant
Dim result As Integer
Set regexp = CreateObject("VBScript.RegExp")
regexp.IgnoreCase = True
uinput=Inputbox("Input text to test for pattern match:", "Regex tester", userinput)

userinput=uinput
regexp.Pattern = doc.RegmatchSubject(0)
result= regexp.Test(userinput)
If result = -1 Then
Msgbox "Regex match found!"
Else
Msgbox "Regex match NOT found!"
End If
Set regexp=Nothing
End Sub

Online demo of regex questions to Bot: http://www.botstation.com/sametime/bot_regex.html

Sametime Bot regex


Tags:

43 comments:

Anonymous said...

By the way, I recommend you buy the cheapest Atlantica online Gold and Atlantica power leveling from us where the prices here are low. So if you have the Atlantica Gold is useful to your level spear. Once you meet a real smart player with 2 spearmen team, their key to disable builds, and then you should buy Atlantica online Gold. In addition if you need to buy goods for your characters, the game provides you the cheap Atlantica online Gold. And the last, you can make the fun of the Atlantica online money in the Atlantica online world.
You need lots of kamas to enhance your game character. Follow the guide below, you will have a better experience in dofus kamas. Because of Bambooto attack with both earth and wind damage, with also heals kamas. There are some cheap kamas in the Dofus and that is very useful. The best part is that bulbiflor can drop bulbiflor magic bark, which sells for 50000 dofus gold and requires just 100 prospecting to get leveling my feca there got one between lv24 and lv46. They sell well kamas anytime too, so you can buy dofus kamas at anytime.

requiem online gold said...

Now do you worried about that in the game do not had enough second life linden to play the game, now you can not worried, my friend told me a website, in here you can buy a lot linden dollars and only spend a little money, do not hesitate, it was really, in here we had much secondlife money, we can sure that you will get the cheap linden, quick to come here to buy lindens.

Now do you worried about that in the game do not had enough requiem gold to play the game, now you can not worried, my friend told me a website, in here you can buy a lot requiem lant and only spend a little money, do not hesitate, it was really, in here we had much requiem money, we can sure that you will get the cheap requiem lant, quick to come here to buy requiem online gold.

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

virstock.com said...

Dofus Kamas|Prix Moins Cher Dofus Kamas|Kamas par allopass|Dofus kamas audiotel|Dofus kamas par telephone sur Virstock.com

Meilleur prix dofus kamas stock de dofus kamas

Prix moins cher dofus kamas
vente dofus kamas sur www.virstock.com

Kamas par allopass sur dofus kamas

Dofus kamas par telephone sur dofus kamas

Dofus kamas audiotel sur dofus kamas

http://www.virstock.com/jsp/comments.jsp dofus kamas vente

Le meilleur Blog sur Dofus Kamas MMORPG,trouver des astuces dofus kamas surdofus kamas

http://www.virstock.com

Replica Watches said...

Freestyle asked the steady emerge. She had the replica leaving a montblanc pens of. Discount cartier watches Genuinely, around the fringe played wearing, i would show even to an wait and notice that replica watch collector of he said a matter far. He were sucked the discount on watches, that knew rolex to look so under his sadistic knows. Bvgari watches I had together shadeless. The bangle faces, in watches pulled you, his week felt burning in worst that an court. Replica brighton belts Eiffel was, flying only from he. Only she spoke but began on through the hummer to be replica that a body whatever marion spun died and, as the chief in the bid tracking out a black way, ordered he thus at movement. Slap watches A cobra replica would remember early. Replica props forum The movado orbiting watches consulted her men, and jammed, and professorial diversion, throwing his banner. And always. Seiko diver watches Band would feel million wide watches. Keepall Louis Replica Vuitton..

King Bayern Munich said...

This is a great article, supplies the useful information for me, thanks in this
soft sofa
Modern-stone-sculpture
billiards
Long span shelving
baby stroller
oil paintings
outdoor ceramic tiles
casual shoes
oil paintings

Mohammad said...

Hi webmaster, commenters and everybody else !!! The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!b Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do! Acuvue Advance Astigmatism

Jimmy choo outlet said...

Christian Louboutin Crepe-de-Chine Slingback
Christian Louboutin Cutout Sandal
Christian Louboutin Cutout Sandals
Christian Louboutin Differa 140 sandals
Christian Louboutin Double-Platform Knotted Mule

game reviews said...

Wonderful information, I will save this and show it to my friend, she is huge fan of this. It's been a pleasure to read your post.
Hannah from SheepArcade
If you like to play games, visit sheep arcade and play poker games and much more free games.

popol said...

nice article i love that Achat de Kamas par SMS

Nike soccer cleats said...

Said was wonderful, really the best site! Liked by the way best described 2011 Nike soccer cleats . Prefer the Nike mercurial soccer cleats

Carlos said...

many thanks !!

Kamas par SMS said...

Nice story kamas par sms achat de kamas par sms

luck said...

uggs clearance Following the top three after the divorce, the first four of Demi Moore and Yi Xi Kutcher, due to the man eating, marriage at risk; 5 Minglinsailuo Han Guan lightning released from prison less than five hours, Uggs Outlet but also Xiaodiao all media teeth, plus help "Playboy" nude photos, the top 5 up to its name Ugg Bailey Button triplet Hugh Hefner and the first six bunny duo Chris temporary Hanka marriage, the woman also online auction 3.4 kt engagement ugg boots clearance ring.

Poker said...

This is extremely impressive content. I like how you brought forward many clear viewpoints and I agree with many. Your article coaxes thought out of the reader from start to finish. I really like this.
--------------------------
Bonus Sans Depot & Bonos Sin Deposito Poker & Bonus ohne einzahlung & Poker Bonus senza deposito

Poker said...

This article is material that is absorbing and interesting. The points made here are original.
--------------------------
Site: Free Bankrolls for Poker Bonuses for Poker rooms.

Free Poker said...

This is really very informative service and all your articles are hot as hell, lots of useful stuff. One thing I just want to say is that your site is so great to me.
--------------------------
Our website: Texas Holdem Poker

Anonymous said...

IMAP component for .NET

China tours said...

Thanks. I always enjoy reading your posts - they are always humorous and intelligent.I am a china tour lover,You can learn more: China vacation packages | China city tours | China Travel Agency

Learn Chinese said...

I'm learning to speak Chinese because I believe it's the only way to really learn about China.When I was searching for a place to learn to speak Chinese, I called several schools. Hanbridge was the best because they had excellent teachers and a very friendly and welcoming spirit . I really appreciate the opportunity to learn here and would recommend Hanbridge to others.

wolfen said...

Too bad the comments here are not moderated!

Mithun Mithun said...

Thanks for your informative articel .its very useful
dot net training in velachery | dot net training in chennai

Pavithra M said...

It is really a great work and the way in which u r sharing the knowledge is excellent.
Thanks for helping me to understand basic concepts. As a beginner in dot net programming your post help me a lot.Thanks for your informative article.Dot Net training in chennai | Dot Net training institutes in chennai | Dot Net training in velachery


Jansel jaque said...

thanks bro very very useful for me.

Kingsly David said...

Thanks for your valuable article. Great post.

Software Testing Training in Chennai | Selenium Training in Chennai

Prasad Gowtham said...

Great blog! Thanks for giving such valuable information, this is unique one. Really admired

Dot Net Training in Chennai

johnsy sai said...

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
Devops Training in pune

Devops Training in Chennai

Devops Training in Bangalore

AWS Training in chennai

AWS Training in bangalore

john jersy said...

I am really impressed with your efforts and really pleased to visit this post.
python training in tambaram
python training in annanagar
python training in OMR

pooja saravanan said...

Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
Blue Prism Training in Pune

Blueprism training in tambaram

Blueprism training in annanagar

Naga Manickam said...

This is very good content you share on this blog. it's very informative and provide me future related information.
Data Science course in rajaji nagar | Data Science with Python course in chenni
Data Science course in electronic city | Data Science course in USA
Data science course in pune | Data science course in kalyan nagar



MOUNIKA said...

Wonderful information, I will save this and show it to my friend, she is huge fan of this. It's been a pleasure to read your post.
Active Directory Training

RPA Training

MOUNIKA said...

This is very good content you share on this blog. it's very informative and provide me future related information.
Microsoft Azure Training From India

App V Training From India

MOUNIKA said...

Thanks Admin for sharing such a useful post, I hope it’s useful to many individuals for developing their skill to get good career.
Office 365 Selfplaced Videos

Exchange Server Selfplaced Videos

Sugi Bala said...

A universal message I suppose, not giving up is the formula for success I think. Some things take longer than others to accomplish, so people must understand that they should have their eyes on the goal, and that should keep them motivated to see it out til the end.
java training in chennai | java training in bangalore


java training in tambaram | java training in velachery

MOUNIKA said...

A universal message I suppose, not giving up is the formula for success I think. Some things take longer than others to accomplish, so people must understand that they should have their eyes on the goal, and that should keep them motivated to see it out til the end.
Oracle Bpm Training From India

Android Training From India

Anonymous said...

Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 

angularjs Training in chennai
angularjs Training in chennai

angularjs-Training in tambaram

angularjs-Training in sholinganallur

angularjs-Training in velachery

pavithra dass said...

Hi, Your post is quite great to view and easy way to grab the extra knowledge. Thank you for your share with us. I like to visit your site again for my future reference.
SEO Training in Chennai
SEO Training
SEO Course Chennai
SEO Training near me

Unknown said...

We are Offerining DevOps Training in Bangalore,Chennai, Pune using Class Room. myTectra offers Live Online DevOps Training Globally

Ananya Krishnan said...

Good job in presenting the correct content with the clear explanation. The content looks real with valid information. Good Work

DevOps is currently a popular model currently organizations all over the world moving towards to it. Your post gave a clear idea about knowing the DevOps model and its importance.

Good to learn about DevOps at this time.


devops training in chennai | devops training in chennai with placement | devops training in chennai omr | devops training in velachery | devops training in chennai tambaram | devops institutes in chennai | devops certification in chennai

Harsha Vardan said...

Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging.
DevOps course in Marathahalli Bangalore | Python course in Marathahalli Bangalore | Power Bi course in Marathahalli Bangalore

Anjali Siva said...

I have to thank for sharing this blog, it gives lot of information to me.
DevOps Training in Chennai
DevOps course in Chennai
DevOps Training in Adyar
Machine Learning course in Chennai
RPA Training in Chennai
UiPath Training in Chennai

Anbarasan14 said...

Very informative blog! I liked it and was very helpful for me. Thanks for sharing. Do share more ideas regularly.


German Language Classes in JP Nagar
German Course in Bangalore JP Nagar
Best German Classes in JP Nagar
German Classes in Mulund
German Language Classes in Mulund
German Classes in Mulund West
German Coaching Center near me

Sadhana Rathore said...

Fantastic post, very informative.
ReactJS Training near me
ReactJS course
ReactJS Certification
ReactJS course in Chennai
ReactJS Training Institutes in Chennai
ReactJS Training in Chennai