[英]Regex: match “:” and “-” but don't match “I-”
Ohare:Montrose:I-290 Circle:IL:IL
Ohare-Montrose-I_290-Circle-IL-IL
EB:Kennedy Expy:O'Hare:IL-43 (Harlem Ave):IL:IL
NB:I-894/US-45:Hale Interchange:Zoo Interchange:WI:IL
NB NB
I-894/US-45 I-894 / US-45
Hale 黑尔
Interchange 立交
Zoo Interchange 动物园互换
WI WI
IL IL
WB:Indiana-East-West:Eastpoint:Middlebury:IN:25:IL
WB WB
Indiana-East-West 印第安纳东西
Eastpoint 置邦
Middlebury 明德
IN 在
25 25
IL IL
Trying to extract words from two different sources that use different conventions. 试图从使用不同约定的两个不同来源中提取单词。
Using regex for that, I cannot create one regex that deals with both options. 为此使用正则表达式,我无法创建一个同时处理这两个选项的正则表达式。
If I try to extract using :
or -
then the first one gets extracted as 如果我尝试使用
:
或-
提取,则第一个提取为
Ohare, Montrose, I, 290 Circle, IL, IL
How can I get a regex to split on :
or -
but ignore I-
or ignore 'IL-', 'US-', 'Indiana-East-West' and many other that I may find? 如何获得正则表达式以进行拆分
:
或-
但忽略I-
或忽略'IL-','US-','Indiana-East-West'和我可能发现的许多其他内容?
What I have so far but not working as I want Regex 我迄今但不工作,我想正则表达式
You can use this negative lookbehind regex: 您可以在正则表达式后面使用此否定式:
(?:(?:IL?|US)-|Indiana-East-West)(*SKIP)(*F)|[:-]
Example Code: 示例代码:
$s = 'NB:I-894/US-45:Hale Interchange:Zoo Interchange:WI:IL';
print_r(preg_split('/(?:(?:IL?|US)-|Indiana-East-West)(*SKIP)(*F)|[:-]/' , $s));
Array
(
[0] => NB
[1] => I-894/US-45
[2] => Hale Interchange
[3] => Zoo Interchange
[4] => WI
[5] => IL
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.