Regex to find Second Char - Alpha followed by 1 digit

Regex to find Second Char is alpha to 5 alpha followed by 1 digit.

thank

-4


source to share


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


.\w{1,5}\d

      



any character followed by 1 to 5 letters, then 1 number

0


source


Double check ...

  • The second character is alpha
  • up to 5 next alphas (i.e. 1 - 6 alphas in total)
  • final number

Yes?

Assuming the first character doesn't matter:

/.[A-Za-z]{1,6}\d/

      

0


source


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







All Articles