Solved

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

Posted on 2011-03-15
4
229 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 74

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

746 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

13 Experts available now in Live!

Get 1:1 Help Now