Regex to Find Second Char is Alpha up to 5 Alpha Followed by 1 numeral.
查找第二个字符的正则表达式是高达5 Alpha的Alpha,后跟1个数字。
Thanks
4 个解决方案
#1
1
I was not successful in implementing any of the solutions above, probably my poor explanation of need. I did solve it in code not using Regex. Thanks to everyone who took the time to help. For those that thought this was homework, it was not.
我没有成功实施上述任何解决方案,可能是我对需求的不良解释。我确实在不使用Regex的代码中解决了它。感谢所有花时间提供帮助的人。对于那些认为这是家庭作业的人来说,事实并非如此。
Here is some sample data.
这是一些示例数据。
Need this
I INDY2 ' INDY VECTOR DP FOR FILING '041802 REM 59268640 I JODUB3 ' AIRWAY FOR JODUB SID '051205 CLW 59268649
I INDY2'INDY VECTOR DP FOR FILING'041802 REM 59268640 I JODUB3'AIRWAY FOR JODUB SID'051205 CLW 59268649
Don't need this
不需要这个
I J149 ' GDK 59265224 I APE074 ' 43092 REF 59265777
I J149'GDK 59265224 I APE074'43092 REF 59265777
This is how I tested in 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
#2
0
Double-checking...
- 2nd character is alpha
- up to 5 following alpha (i.e., total 1 - 6 alpha)
- final numeric
第二个字符是alpha
最多5个跟随alpha(即总共1 - 6 alpha)
Yes?
Assuming first character is irrelevant:
假设第一个字符无关紧要:
/.[A-Za-z]{1,6}\d/
#3
0
.\w{1,5}\d
any character followed by between 1 and 5 letters then 1 number
任何字符后跟1到5个字母,然后是1个数字
#4
-1
This should do the trick. Regular expression language is .Net implementation
这应该可以解决问题。正则表达式语言是.Net实现
^.[a-zA-Z]{1,5}\d$
Breakdown
- ^ force the match to start at the begining of the text
- . will match anything
-
[a-zA-Z
]{1,5
} will match any character a-z at least one time but no more than five. Because of the preceeding "." this means that the match will start at the second character - \d matches a single digit
- $ matches the end of the text
^强制匹配从文本的开头开始
。会匹配任何东西
[a-zA-Z] {1,5}将匹配任何字符a-z至少一次但不超过五次。由于前面的“。”这意味着匹配将从第二个角色开始
\ d匹配一个数字
$匹配文本的结尾
#1
1
I was not successful in implementing any of the solutions above, probably my poor explanation of need. I did solve it in code not using Regex. Thanks to everyone who took the time to help. For those that thought this was homework, it was not.
我没有成功实施上述任何解决方案,可能是我对需求的不良解释。我确实在不使用Regex的代码中解决了它。感谢所有花时间提供帮助的人。对于那些认为这是家庭作业的人来说,事实并非如此。
Here is some sample data.
这是一些示例数据。
Need this
I INDY2 ' INDY VECTOR DP FOR FILING '041802 REM 59268640 I JODUB3 ' AIRWAY FOR JODUB SID '051205 CLW 59268649
I INDY2'INDY VECTOR DP FOR FILING'041802 REM 59268640 I JODUB3'AIRWAY FOR JODUB SID'051205 CLW 59268649
Don't need this
不需要这个
I J149 ' GDK 59265224 I APE074 ' 43092 REF 59265777
I J149'GDK 59265224 I APE074'43092 REF 59265777
This is how I tested in 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
#2
0
Double-checking...
- 2nd character is alpha
- up to 5 following alpha (i.e., total 1 - 6 alpha)
- final numeric
第二个字符是alpha
最多5个跟随alpha(即总共1 - 6 alpha)
Yes?
Assuming first character is irrelevant:
假设第一个字符无关紧要:
/.[A-Za-z]{1,6}\d/
#3
0
.\w{1,5}\d
any character followed by between 1 and 5 letters then 1 number
任何字符后跟1到5个字母,然后是1个数字
#4
-1
This should do the trick. Regular expression language is .Net implementation
这应该可以解决问题。正则表达式语言是.Net实现
^.[a-zA-Z]{1,5}\d$
Breakdown
- ^ force the match to start at the begining of the text
- . will match anything
-
[a-zA-Z
]{1,5
} will match any character a-z at least one time but no more than five. Because of the preceeding "." this means that the match will start at the second character - \d matches a single digit
- $ matches the end of the text
^强制匹配从文本的开头开始
。会匹配任何东西
[a-zA-Z] {1,5}将匹配任何字符a-z至少一次但不超过五次。由于前面的“。”这意味着匹配将从第二个角色开始
\ d匹配一个数字
$匹配文本的结尾