Link to home
Start Free TrialLog in
Avatar of Fordraiders
FordraidersFlag for United States of America

asked on

Regex Expression Updated for alphaNumeric or Numeric sequences

VB.NET 2003

Right now the regex below is not pulling these number sequences (below)
Question:
1. I did not know if some of the regex expressions I have here will work.

' code ====================================================
With dbDataSet.Tables("tblData")
            For Each dbRow As Data.DataRow In dbDataSet.Tables("tblData").Rows

  Dim input As String = dbRow.Item("fldDescription")
 Dim pattern1 As String = "(\s|^)(\d\w{3,}|\w(?=\w*?\d)\w{3,})(\s|$)" '4 or more in Digit/AlphaNumx 3 in length
'Dim pattern1 As String = "(\s|^)(\d\w{3,})(\s|$)"  '4 or more in Digit/AlphaNumx 3 in length
'Dim pattern As String = "(\s|^)(\d{4,})(\s|$)" '4 or more in length
'Dim pattern As String = "(\s|^)(\d+)(\s|$)" ' WORKING for anynumber
'Dim pattern As String = "(\s+\d+\s+)"
               Dim mc As MatchCollection = Regex.Matches(input, pattern1)
               Dim output As String = ""
                Dim trimStr() As Char = {" "c, ":"c}
                For Each m As Match In mc
                    output &= m.Groups(0).Value & " : "
                 
                Next
                ' Remove the last " : " in the output string.
                dbRow.Item("fldMfrnum") = output.TrimEnd(trimStr)
                         Next
' =code =======================================


SHEAVE , PT-H504 , IDLE
PULLEY , SLG125S ,  1/2 INCH
FUSE ,  125S ,  GLASS
PULLEY , PT-I303
BUSHING , PT-F902
BUSHING , PT-N604 , IDLE
FUSE ,  W24 , 7 AMP
FUSE , w56 , 5 AMP
V-BELT  , B81
V-BELT ,  A-45
MASKING TAPE , 41-3220-0 , 1/2 INCH ROLE

PT-H504
SLG125S
125S
PT-I303
PT-F902
PT-N604
W24
w56
B81
A45
41-3220-0

Trying to match additional numbers embedded in strings
Thanks
fordraiders

Avatar of ozo
ozo
Flag of United States of America image

Dim pattern1 As String = "([-\w]+\d)"  
> V-BELT ,  A-45

> A45

Did you mean A-45
SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Fordraiders

ASKER

ozo, Either  or...
A-45  or  a45
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ozo, working really good, except  pulling in  (   ) with the string
example:
01-0111-0057  BELT - CONVEYOR  (SP6301-96)
pulling:
01-0111-0057  :  (SP6301-96)
should be
01-0111-0057  :  SP6301-96



Fernando, Working great..but seems to not pull in  just a strainght numeric sequence...?
example:
 01-0111-0057  BELT - CONVEYOR  (SP6301-96) SP6301-96  PT -NEED-BIN 3 6 EA 6 44.2 265.2

Pulled:
01-0111-0057 : SP6301-96 : SP6301-96

for this line:
 01-0093-0031  BELT  , TIMMIMG (617210142040) UnKnown PT-NEED-BIN

it only pulled out:
01-0093-0031

Should have also been:
01-0093-0031 : 617210142040


Thanks to both really good stuff !

Hi fordraiders:

You say it did not pull out a straight numeric sequence from this

    01-0093-0031  BELT  , TIMMIMG (617210142040) UnKnown PT-NEED-BIN

meaning it did not catch this 617210142040.

Does that mean that you want to catch all numeric sequence as your other example:

 01-0111-0057  BELT - CONVEYOR  (SP6301-96) SP6301-96  PT -NEED-BIN 3 6 EA 6 44.2 265.2

You want to catch from this part of the string, 3 6 EA 6 44.2 265.2, the 3 and 6 and 6 and 44.2 265.2 as well?

Fernando

ozo,
How difficult would it be to change this to accept just patterns matches for 4 or more in the string match.
Dim pattern1 As String = "(\S*\d\d\S*)"
Fernando:
No because that would cause alot of junk.
numeric sequence of 4 or more digits would be good
Dim pattern As String = "(\s|^)(\d{4,})(\s|$)"
I think this would work?

===============================================
It would be great to run your sequence...or ozo
and then rerun it again with just the numeric match and add on the the items already in the field...
===============================================

four digits in a row would not pull out
PT-H504
SLG125S
125S
PT-I303
PT-F902
PT-N604
W24
w56
B81
A45
Those examples are alpha numeric strings
PT-H504
SLG125S
125S
PT-I303
PT-F902
PT-N604
W24
w56
B81
A45
I though those were examples of what you wanted the expression to match.
Could you give some illustrative examples of what you want to match or not match?
Yes, I want match those, but also
for numerics
4355
6565744
4344343
43434
43434
4444
would
Dim pattern As String = "(\d{4,})"
suffice for that?
sure,
Thanks
Hi fordraiders;

Try this pattern it should give you all you now want.

    Dim pattern1 As String = "(?i)(([A-Z-]+[0-9]+|[0-9]+[A-Z-]+)[A-Z0-9-]*)|(?:\s|^)\d{4,}(?=\s)"

Fernando