Regex to find Second Char - Alpha followed by 1 digit
4 answers
I have failed to implement any of the above solutions, perhaps my poor explanation of the need. I solved this in code without using Regex. Thanks to everyone who took the time to help. For those who thought it was homework, it was not.
Here are some sample data.
Need this
I INDY2 'INDY VECTOR DP FOR FILING' 041802 REM 59268640 I JODUB3 'AIRWAY FOR JODUB SID' 051205 CLW 59268649
Don't need it
I J149 'GDK 59265224 I APE074' 43092 REF 59265777
This is how I tested the code.
Dim IsSidStar As Boolean = False
If aAirways.Name.Length > 2 Then
Dim a2ndChar As Char = aAirways.Name(1)
Dim alastChar As Char = aAirways.Name(aAirways.Name.ToString.Length - 1)
Dim a2ndlastChar As Char = aAirways.Name(aAirways.Name.ToString.Length - 2)
If Char.IsLetter(a2ndChar) = True AndAlso Char.IsNumber(alastChar) = True AndAlso Char.IsNumber(a2ndlastChar) = False Then
IsSidStar = True
End If
End If
+1
source to share
This should do the trick. The regex language is a .Net implementation.
^. [A-Za-Z] {1,5} \ d $
Structure
- ^ makes the match start from the beginning of the text
- ... will fit all
-
[a-zA-Z
]{1,5
} will match any character az at least once, but no more than five. Because of the preceding "." this means that the match will start at the second character. - \ d matches one digit
- $ matches end of text
-1
source to share