简体   繁体   English

使用正则表达式匹配地址与目标部分不匹配

[英]matching an address with regex doesn't match the target part

I'm not quite good in regex. 正则表达式我不是很好。

With my input string LT 1 BLK 4 LAKES OF PARKWAY 5 R/P & AMEND 我的输入字符串LT 1 BLK 4 LAKES OF PARKWAY 5 R/P & AMEND

I'd like to match just the only part between the figure 4 and 5 in the string. 我想匹配字符串中图45之间的唯一部分。

meaning that, my expected result is LAKES OF PARKWAY . 意思是,我的预期结果是LAKES OF PARKWAY

I've tried to come up with a pattern to get such result. 我试图想出一个模式来获得这样的结果。

 \d+\s+([A-z ]+)(\d+.*?)*$

but with my pattern, it only matches BLK and 5 R/P & AMEND , as group #1 and group #2 respectively. 但是对于我的模式,它只匹配BLK5 R/P & AMEND ,分别作为组#1和组#2。 At the end of my thought pattern, I decide to use end of string matching, $ . 在我的思维模式结束时,我决定使用字符串匹配结束, $ So, when 5 R/P & AMEND got matched, the pointer should move further behind to the sub sequence part. 因此,当5 R/P & AMEND匹配时,指针应该进一步向后移动到子序列部分。 Then, ([Az ]+) should match LAKES OF PARKWAY . 然后, ([Az ]+)应匹配LAKES OF PARKWAY

What's wrong with my pattern? 我的模式有什么问题? and how to get it to work? 以及如何让它工作?

Any advice would be very much appreciated. 任何建议将非常感谢。

Try \\d+\\s+(\\D+)\\d+\\D*$ 尝试\\d+\\s+(\\D+)\\d+\\D*$

\\D means 'anything that is not \\d , so it won't be allowed to match, for example, between the first 1 and 4, because then the ending of the regex would be rejected at the later 5 . \\D表示'任何不是\\d的东西,所以它不会被允许匹配,例如,在第一个和第一个之间,因为那时正则表达式的结尾将在后面的5被拒绝。

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

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