John Carney
asked on
Tweaking a RegEx function so that it excludes certain patterns that might otherwise be matches, and more.
In the code below, how do I limit my accepted alphanumerics to ones containing no more than 3 digits, and how do I exclude cells - that would otherwise match the pattern - if certain strings are also present?
I thought that this line would accomplish both of these things but it doesn't:
.Pattern = "(\d+)[ /-]?(?!jan|feb|apr|ma[ry]| ju[ln]|aug |sep|oct|n ov|dec|in| by|mi|hrs| check|GMT| jump|and)[ A-M]+"
Finally, how would I combine the two patterns below into one. Or at least position them within the same IF statement. Assuming that's possible.
I've attached a workbook if that helps.
Thanks,
John
I thought that this line would accomplish both of these things but it doesn't:
.Pattern = "(\d+)[ /-]?(?!jan|feb|apr|ma[ry]|
Finally, how would I combine the two patterns below into one. Or at least position them within the same IF statement. Assuming that's possible.
I've attached a workbook if that helps.
Thanks,
John
Function getSeats(InputCell As Range) As String
Dim RegEx, RegM, RegMC
Dim MyDic
Dim tmpStr As String
Dim i As Long
Set MyDic = CreateObject("scripting.dictionary")
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
.Pattern = "(?:ROW|SEAT)(S)?\s*(\d+)\s*([,-/|]|to|thru|through)\s*(\d+)"
.Global = False
.IgnoreCase = True
If .test(InputCell.Value) Then
Set RegMC = .Execute(InputCell)
For Each RegM In RegMC
tmpStr = "PAX"
Next
End If
'How do I combine the pattern above with this one?
.Pattern = "(\d+)[ /-]?(?!jan|feb|apr|ma[ry]|ju[ln]|aug|sep|oct|nov|dec|in|by|mi|hrs|check|GMT|jump|and)[A-M]+"
.Global = False
.IgnoreCase = True
If .test(InputCell.Value) Then
Set RegMC = .Execute(InputCell)
For Each RegM In RegMC
tmpStr = "PAX"
Next
End If
getSeats = tmpStr
End With
End Function
GetSeatCodes.xls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I see you've had several other posts over the last couple days and may not have gotten back to this. Was what I submitted any help?
Do you still need RegEx help? I can assist further, now, especially if you can give me a dataset of inputs and what the outputs are supposed to look like. That way I can do some testing with your input. Re: its abit hard to take on the challenge of fixing a RegEx by interpreting what it does without knowing what its supposed to do after tweaks, if my proposed approach wasn't satisfactory...
PS - did the combination into one IF statement work fine for you?
Dave
Do you still need RegEx help? I can assist further, now, especially if you can give me a dataset of inputs and what the outputs are supposed to look like. That way I can do some testing with your input. Re: its abit hard to take on the challenge of fixing a RegEx by interpreting what it does without knowing what its supposed to do after tweaks, if my proposed approach wasn't satisfactory...
PS - did the combination into one IF statement work fine for you?
Dave
ASKER
Hi Dave, pls forgive me for being AWOL. I'm pretty hopeful that your solutions will solve my problem. I'm going to email myself to check this out firstthing tomorrow morning at work.
Thanks,
John
Thanks,
John
ASKER
Thanks, Dave. I'm still not completely out of the woods, but this will definitely get me started. Stay tuned!
- John
- John
Open in new window
PS - it looks like you got some help with this initial function - you might go back to that posting and post a link to this one to reel them in :)
Dave