regex - 如何使用正则表达式排序?
问题描述
/(summer camp)|(summer)|(camp)/
Forest camp
summer ramadan
summer camp
summer rakatun
我在链接“夏令营”、“夏令营”、“夏令营”上有测试数据,我需要做一个正则表达式,让“夏令营”成为第一个匹配项
regexp 有一个匹配的搜索顺序,我需要第一个匹配来找到夏令营,尽管它在列表中排名第三。但现在是第一场“阵营”比赛。
解决方案
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)?)?
推荐阅读
- jquery - 如何限制 AutoNumeric 负值的输入?
- python - 需要正则表达式来避免“\n”字符
- php - 如何为 5 个不同的 WordPress 帖子组设置样式
- python - 以下类没有基本事实示例
- c++ - 基于航拍图像的地面机器人障碍物检测
- computational-geometry - 列举所有基本可行的解决方案
- php - 我如何设置一个在 php 中调用 24 小时后运行的函数?
- android - 房间。如何在数据库中存储动态字段?
- scala - 我们可以用 List 在 Scala 中创建辅助构造函数吗?
- python - 与用于编写解析器的最终结构类似的 dict 结构