我想提取远程信息素编号,但仅匹配Place C
,但不匹配Place A
和Place B
。有人可以帮我弄这个吗?预先感谢!
Regex
(.+?)\s*(\d+.*Singapore\s+\d{6}\b|\d+.*S\d{6})\b(?!(\.+?)\s*)(\+65[\d ]*)
文本
Place A
2 Bayfront Avenue Galleria Level #B1-01 Singapore 018972 Tel: +65 6634 9969
Place B
23 Serangoon Central #B1-10 Singapore 556083 Phone: +65 6634 7787
Place C
1 Northpoint Drive South Wing #B1-107 Singapore 768019+65 6481 3433
在6位数字和电话号码之间,可以有一个标签,因此您需要对此加以说明并以某种方式使用它。为此,一个示例是允许任意字符存在,而不是+
符号,如下所示:
[^+]*
在您的正则表达式中,做到了:
(.+?)\s*(\d+.*Singapore\s+\d{6}\b|\d+.*S\d{6})\b(?!(\.+?)\s*)[^+]*(\+65[\d ]*)
now matches全部三种情况。