regex - 使用正则表达式从具有已知前缀的字符串中提取多个单词
问题描述
我有以下输入
Obvious directions are:
west, east, southeast, south.
...并希望得到以下输出:
west
east
southeast
south
为我做这件事的神奇正则表达式是什么?
我已经提取了第一个标记,west
所以我认为我需要一个乘数/递归/某物或其他东西,但我一生都找不到什么。
(?<= Obvious directions are:\s+)(\w+)(?=[,\.])
解决方案
采用
(?<=Obvious directions are:[^.]*?)\w+
见证明。
解释
--------------------------------------------------------------------------------
(?<= look behind to see if there is:
--------------------------------------------------------------------------------
Obvious directions 'Obvious directions are:'
are:
--------------------------------------------------------------------------------
[^.]*? any character except: '.' (0 or more
times (matching the least amount
possible))
--------------------------------------------------------------------------------
) end of look-behind
--------------------------------------------------------------------------------
\w+ word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the most amount
possible))
推荐阅读
- amazon-web-services - 没有响应或输出运行 aws 命令
- css - 浮动时引导进度条消失
- java - Java父类使用子类属性
- python - Python:如何使圆变大和变小
- reactjs - 在没有道具的 Typescript 中使用 React.forwardRef
- javascript - 如何使用数组或对象显示消息
- javascript - 仅当子元素存在时隐藏元素
- elasticsearch - 弹性搜索索引上的多个分析器
- database - 将 Postgres DB 中的 2 个模式与不同的飞行路径合并
- javascript - 我需要一些帮助来验证 javascript 中的以下代码