Hello,
Hopefully someone can help me with what i assume is a simple regex problem, but I don't seem to be having any luck with.
Basically i have a string, which has a IncidentID in it which is usually a letter followed by a string of numbers (e.g. E13101710393,F131008246 or S131036382) what i would like to do is to check the string for a regex match based on having either E and numbers, F and numbers, or S and Numbers however i am having a few issues.
I have the regex working with either E(\d*), F(\d*) or S(\d*) however my issue becomes that for some reason (at least on the online testers) is that it will match the letter seperate to the numbers, so if E appears in the string at all then it thinks there is a match. How can i get it to only match is there is E and a series of numbers after it (say more than 3 numbers) up to 15 numbers.
Below is my script, however as mentioned it is the specific regex that has me confused, so anyone could make some suggestions on how to match a letter than a series of more than a few numbers (up to say 10) it would be greatly appreciated.
Hopefully someone can help me with what i assume is a simple regex problem, but I don't seem to be having any luck with.
Basically i have a string, which has a IncidentID in it which is usually a letter followed by a string of numbers (e.g. E13101710393,F131008246 or S131036382) what i would like to do is to check the string for a regex match based on having either E and numbers, F and numbers, or S and Numbers however i am having a few issues.
I have the regex working with either E(\d*), F(\d*) or S(\d*) however my issue becomes that for some reason (at least on the online testers) is that it will match the letter seperate to the numbers, so if E appears in the string at all then it thinks there is a match. How can i get it to only match is there is E and a series of numbers after it (say more than 3 numbers) up to 15 numbers.
Below is my script, however as mentioned it is the specific regex that has me confused, so anyone could make some suggestions on how to match a letter than a series of more than a few numbers (up to say 10) it would be greatly appreciated.
PHP Code:
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.IO
Sub Extract(parm as object)
Try
Dim InputStr as String = parm.ToString
if InputStr = Nothing then Exit Sub
Dim regex As Regex = New Regex("@@E(\d*)|HbE(\d*)|E(\d*)") 'Ambulance Call
Dim regex1 as Regex = New Regex("@@S(\d*)|HbS(\d*)|S(\d*)") 'SES Call
Dim regex2 as Regex = New Regex("@@ALERT F(\d*)|HbF(\d*)|F(\d*)") 'CFA Call
Dim Agency as String = ""
Dim match As Match = regex.Match(InputStr)
if Match.Success = True
Agency = "Ambulance"
end if
Dim match1 As Match = regex1.Match(InputStr)
if Match.Success = True
Agency = "SES"
end if
Dim match2 As Match = regex2.Match(InputStr)
if Match.Success = True
Agency = "CFA"
end if
if Agency = "" then
Agency = "Unknown"
end if
hs.writelog("Agency","Agency: " & Agency)
Catch ex As Exception
hs.writelog("ExtractAddress.vb Error",ex.Message)
End Try
End Sub
Comment