-
Regular expressions
I'm trying to use regex, but can't seem to get the pattern right. Here's my objective:
I need a pattern that will match any phrase that starts with "f", has zero or more spaces and has "ch" or letter combination very close to that. The length should be 17+ characters
I'm parsing this string: "furniture checklist"
this is my pattern so far: [VBA]"^(f\b+)\s*((c?h)|(ce)|(h?c))\D$"[/VBA] it returns an error. If I remove \b, then it doesn't, but that loses "any word that starts with F".
Here's my complete code example:
[VBA]Sub Macro3()
Dim RegEx As Object, x As String, result As Boolean
Set RegEx = CreateObject("vbscript.regexp")
x = "furniture checklist"
RegEx.Pattern = "^(f\b+)\s*((c?h)|(ce)|(h?c))\D$"
'RegEx.IgnoreCase = True
result = RegEx.Test(x)
Debug.Print result
End Sub[/VBA]
Help!
-
"^f.*\s.*((c?h)|(ce)|(h?c))\D" seems to do what you need.
Not sure what you have the "\D" for; it only excludes some exotic cases such as "furniture c4".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules