我有以下输入
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))