首页 > 解决方案 > 如何使用正则表达式排序?

问题描述

/(summer camp)|(summer)|(camp)/
Forest camp
summer ramadan
summer camp
summer rakatun

我在链接“夏令营”、“夏令营”、“夏令营”上有测试数据,我需要做一个正则表达式,让“夏令营”成为第一个匹配项

regexp 有一个匹配的搜索顺序,我需要第一个匹配来找到夏令营,尽管它在列表中排名第三。但现在是第一场“阵营”比赛。

https://regex101.com/r/YWgrlO/1/

标签: regexregex-lookarounds

解决方案


regexp has a search order of matches, I need the first match to find a summer camp, despite the fact that it is third on the list. But now the first "camp" match.

不知道你的意思,但如果你想按照优先
顺序找到这些,首先找到夏令营,它会是这样的

(?s)(summer camp)(?:.+?(summer|camp)?)?

https://regex101.com/r/0A7TBD/1


推荐阅读