regex - 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
是否有捷径可寻?
解决方案
比赛部分:
-?\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+)
它利用前瞻来检查前面是否还有两个数字。
推荐阅读
- mysql - 如何从数据库连接表中查询并使用日期或范围之间?
- javascript - Chart.js update() 方法最终只工作一次,而不是每次迭代都更新
- amazon-web-services - 使用 VPN 网关在本地将 AWS EC2 连接到 Google Cloud SQL 实例
- shiny-server - 希望在 R 闪亮的服务器中运行 R GUI
- typescript - 从泛型函数返回空数组
- vim - 方便的单键重新映射,用于在 Vim 中向上翻页和向下翻页
- html - Cordova 内容安全策略 frame-src 错误
- postgresql - 如何将 knex.js 连接到 PostgresSQL 数据库?
- php - 为什么将 null 转换为数组会退出代码?
- mysql - 如何将 MySQL 表从 PhpMyAdmin 复制到不同系统中的 MySQL Workbench?