Solved

RegX alpha Pattern won't process the letter 'H'

Posted on 2011-03-15
4
243 Views
Last Modified: 2012-05-11
The function below analyzes free text and if the text contains a number followed immediately with a letter from A to M, it enters that value in the calling cell. But for some reason it won't extract "31H" from this text:

"BKK/MNL. 31H nad 22E inop, no sound. 4SR/NR"  (In fact it prevents "22E" from displaying as well)

It will display everyalphanumeric combo from 31A to 31M, but not 31H. The really curious thing is that if I change the word "nad" to any other word, then the H works. For example,

"BKK/MNL. 31H supercalifragilisticexpialidocious 22E inop, no sound. 4SR/NR"   does indeed produce  "31H, 22E" in the desired cell.

Is there anything in the fuinction that would explain that?

Thanks,

John :-)
Function GetSeats(InputCell As Range) As String   ' 'brettdj & Brad
    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(S)? (\d+)-(\d+)"
        '.Pattern = "ROW(S)?\s*(\d+)\s*[,-/]\s*?(\d+)" 'Brad
        .Pattern = "ROW(S)?\s*(\d+)\s*([,-/|]|to|thru|through)\s*(\d+)"  'expanded Brad
        .Global = True
        .IgnoreCase = True
        If .test(InputCell.Value) Then
            Set RegMC = .Execute(InputCell)
            For Each RegM In RegMC
                If MyDic.exists(LCase$(RegM)) = False Then
                    For i = RegM.submatches(1) To RegM.submatches(3)
                        Select Case i
                        Case Is <= 4
                            tmpStr = tmpStr & i & "ACDF, "
                        Case Is < 7 > 4
                            tmpStr = tmpStr & i & "ABCDEF, "
                        Case Else
                            tmpStr = tmpStr & i & "ABCDEFHJK, "
                        End Select
                    Next
                    tmpStr = Left$(tmpStr, Len(tmpStr) - 2)
                    MyDic.Add LCase$(RegM), 1
                End If
            Next
        End If
        .Pattern = "\d+[A-M]+"
        If .test(InputCell.Value) Then
            Set RegMC = .Execute(InputCell)
            For Each RegM In RegMC
                If tmpStr = vbNullString Then
                    tmpStr = RegM
                Else
                    tmpStr = tmpStr & ", " & RegM
                End If
            Next
        End If
        GetSeats = tmpStr
    End With
End Function

Open in new window

0
Comment
Question by:gabrielPennyback
4 Comments
 
LVL 35

Accepted Solution

by:
Terry Woods earned 167 total points
ID: 35144027
Note that - is a special character when included in [] brackets, like you've got:
[,-/|]
It's interpreted as:
One character, being either a pipe character or any character between , and /

You can either escape the - or put it at the start or end of the list to avoid the issue:
[-,/|]

However, I can't imagine that causing the issue you describe. I'm not familiar enough with the language to really understand what's happening very easily.
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 167 total points
ID: 35144946
There is nothing particularly strange about your 2nd pattern, so that seems to indicate your data is screwy. Are you sure there aren't any non-printable characters between the numbers and the letters in your data?
0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 166 total points
ID: 35146221
The function works for me on that data, so I'd agree that perhaps you have other chars in there.
0
 
LVL 1

Author Closing Comment

by:gabrielPennyback
ID: 35152469
The ghost is in the machine again. For some reason it's working just fine today. No screwy data, just a screwy computer I guess.

Thanks for the suggestions.

- John
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

867 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

17 Experts available now in Live!

Get 1:1 Help Now