且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

匹配可能存在或可能不存在的组

更新时间:2023-11-26 18:13:10

将正则表达式更改为:

(.*?)\s(\d{5})\s(.+?)\s?(FINLAND|SUOMI)?$

让第三个组没有贪心会让您匹配可选的空格+国家(地区)选择.如果第4组不匹配,我认为它将是未初始化的,而不是空白,这取决于语言.

Making group three none greedy will let you match the optional space + country choices. If group 4 doesn't match I think it will be uninitialized rather than blank, that depends on language.