【发布时间】:2020-12-03 10:14:35
【问题描述】:
什么是匹配在第一个逗号处停止的 URL 字符串的干净正则表达式模式?尝试从 Google 表格中的数组中提取值。
单元格 A1
{https://www.myshop.com/shop/the_first_shop,Marcus. White's. Shop.,ACTIVE,US};{https://www.myshop.com/shop/a-second-shop,The first! Shop,CLOSED,UK};{EMPTY,ClosedShop,CLOSED,IN}
所需输出(单元格 B1)
https://www.myshop.com/shop/the_first_shop,https://www.myshop.com/shop/a-second-shop
我已经想出如何在我想要的输出单元格中获得一个干净的匹配值数组:
=trim(regexreplace(regexreplace(regexreplace(REGEXREPLACE(A2,"/(https?:\/\/[^ ]*)/"," "),";"," "),"}"," "),"{"," "))
但我找不到以逗号结尾的正则表达式模式。比如这个解决方案:
"/(https?:\/\/[^ ]*)/"
匹配第一个 URL,但返回给我:
https://www.myshop.com/shop/the_first_shop,Marcus. White's. Shop.,ACTIVE,US https://www.myshop.com/shop/a-second-shop,The first! Shop,CLOSED,UK EMPTY,ClosedShop,CLOSED,IN
【问题讨论】:
-
分享您的工作表副本以及所需输出的示例
标签: regex google-sheets extract google-sheets-formula string-matching