0

I'm parsing large amounts of textual data using Regular Expressions in VBA within cells of an Excel document using Microsoft VBScript Regular Expressions 5.5.

I can't figure out how to create a Regular Expression phrase that WILL match something that reads: "deploy", "deploying", "deployment" but NOT something that says specifically "redeploy". So far I've tried the below expressions, to no avail:

(^[rR][eE])([dD][eE][pP][lL][oO][yY])
(^[rR][eE])?([dD][eE][pP][lL][oO][yY])
.(^[rR][eE])([dD][eE][pP][lL][oO][yY])
*(^[rR][eE])([dD][eE][pP][lL][oO][yY])

Could anyone spot what I'm doing wrong? Or is this not possible given how Regex functions?

Alex
  • 185
  • 1
  • 1
  • 14
  • Basically, you want to match *deploy*, but not words containing *deploy* ? – Gawil May 30 '17 at 15:12
  • 2
    `"\bdeploy\b"` matches the word exactly by requiring it be surrounded by boundaries if that's what your asking. Also `YourRegExp.IgnoreCase = True` – Alex K. May 30 '17 at 15:12
  • I'm looking to specifically exclude "redeploy". I would include "deploying", "deployment", etc. I apologize for the lack of clarity, OP has been updated. – Alex May 30 '17 at 15:27

3 Answers3

0

Try this regex :
redeploy\w*|(\w*deploy\w*)

The words you are looking for are in the first capturing group. It will capture every words containing deploy but not beginning with redeploy.

You can also try the code below (not tested) :

Dim searchStr As String
searchStr = "redeploy deploying redeployment deploy"
Dim regex As New VBScript_RegExp_55.RegExp
Dim matches
regex.Pattern = "redeploy\w*|(\w*deploy\w*)"
regex.IgnoreCase = True
regex.Global = True
If regex.test(searchStr) Then
    Set matches = regex.Execute(searchStr)
    Dim match As Variant
    For Each match In matches
        Debug.Print match.Submatches(0)
    Next
End If
Gawil
  • 1,171
  • 6
  • 13
0

Use this:

>> Set r = New RegExp
>> r.IgnoreCase = True
>> r.Pattern = "\bdeploy"
>> For Each w In Split("redeploy deploy deploywhatever misdeploy")
>>     WScript.Echo w, CStr(r.Test(w))
>> Next
>>
redeploy Falsch
deploy Wahr
deploywhatever Wahr
misdeploy Falsch
>>

to try if "a word starting with 'deploy'" meets your spec.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
0
"(?!re)\b\S*deploy\S*"

will not match redeploy, but would match, for example misdeploy, as well as the various forms (deployment, deploying, etc)

If you can eliminate all the words that "prefix" deploy, then

"\bdeploy\S*"

would be simpler.

Ron Rosenfeld
  • 53,870
  • 7
  • 28
  • 60