简体   繁体   English

正则表达式-匹配行尾的非数字

[英]Regular expression - match the non digits at the end of a line

I am trying to match the characters at the end of line that contains digits and spaces. 我正在尝试匹配包含数字和空格的行尾的字符。 For example 例如

62 29N 23W 5 WATSON B 62 29N 23W 5屈臣氏B

I'd like to match "WATSON B" 我想搭配“ WATSON B”

but also match "SMITH" in the case of 但在以下情况下也要匹配“ SMITH”:

60 29N 22W 7 SMITH 60 29N 22W 7史密斯

This simple regex should do it: 这个简单的正则表达式应该做到这一点:

([A-Z]+ *)+$

See live demo . 观看现场演示

Not completely sure what you are trying to do but you might want to try something like this: 不能完全确定您要做什么,但是您可能想要尝试如下操作:

\d{1,2} \d{1,2}[a-zA-Z] \d{1,2}[a-zA-Z] \d ([a-zA-Z\s]+)

\\d{1,2} matches a character 1 to 2 times \\d{1,2}匹配一个字符1至2次

\\d{1,2}[a-zA-Z] additionally requires a character \\d{1,2}[a-zA-Z]另外需要一个字符

([a-zA-Z\\s]+) captures the remaining characters if they are letters or a whitespace character ([a-zA-Z\\s]+)捕获其余字符,如果它们是字母或空格字符

This one should do it: [a-zA-Z][a-zA-Z\\s]+$ 这应该做到: [a-zA-Z][a-zA-Z\\s]+$

Made an edit. 进行了编辑。 Initial regex caught space char before name. 初始正则表达式在名称前捕获了空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM