Textwrangler中的正则表达式-删除两个字符之间的字符串

时间:2019-01-31 03:01:05

标签: regex string textwrangler

我有一个文本文件,其中包含流行城市的多个天气统计信息,不仅包括当天的最高和最低值,还包括昨天的天气,如下所示:

City/Town, State;Yesterday’s High Temp (F);Yesterday’s Low Temp (F);Today’s High Temp (F);Today’s Low Temp (F);Weather Condition;Wind Direction;Wind Speed (MPH);Humidity (%);Chance of Precip. (%);UV Index

Atlanta, GA;43;22;44;22;Partly sunny, chilly;NW;9;38%;7%;4
Atlantic City, NJ;45;24;37;9;A snow squall;WNW;22;36%;58%;3
Baltimore, MD;40;23;34;8;A snow squall, windy;NW;19;37%;57%;1
Bismarck, ND;-10;-29;-8;-15;Frigid;SSE;6;73%;58%;2

我希望能够输入一个正则表达式命令,该命令将删除状态后的前两个数字,并删除昨天的高温和低温,使其看起来像这样:

City/Town, State;Yesterday’s High Temp (F);Yesterday’s Low Temp (F);Today’s High Temp (F);Today’s Low Temp (F);Weather Condition;Wind Direction;Wind Speed (MPH);Humidity (%);Chance of Precip. (%);UV Index

Atlanta, GA;44;22;Partly sunny, chilly;NW;9;38%;7%;4
Atlantic City, NJ;37;9;A snow squall;WNW;22;36%;58%;3
Baltimore, MD;34;8;A snow squall, windy;NW;19;37%;57%;1
Bismarck, ND;-8;-15;Frigid;SSE;6;73%;58%;2

有一种简单的方法吗?

1 个答案:

答案 0 :(得分:1)

匹配部分:

-?\d+;-?\d+;(-?\d+;-?\d+)

替代:

$1

打破现状:

Check for possible hyphen
-?
Check for number
\d+
Check for semicolon
;
Do the above again
-?\d+;
Start of capturing group
(
Do above check 2 times again
-?\d+;-?\d+
End of capturing group
)

$1意味着将其替换为第一个捕获组的内容。

如果您不想进行任何替换,也可以使用它:

-?\d+;-?\d+;(?=-?\d+;-?\d+)

它利用超前检查来检查前面是否还有两个数字。