我有一条类似于这样的字符串:"abcd abcd | abcde | Degree SP | xyz abcd | abcd ABC"
我需要使用正则表达式提取"Degree SP"
。我怎么能这么做?这里的条件是:
我正在尝试Google公式REGEXEXTRACT(<input string>, "[\|\s].+SR[\s\|]")
,它返回" | abcde | Degree SP "
。如何才能限制从上一次“\”中提取
发布于 2021-11-17 10:11:25
发布于 2021-11-17 06:41:04
使用您所显示的示例,请尝试使用以下正则表达式。
^.*?\s+\S+\s+\|\s+\S+\s+\|\s+([^\\|]*)\s+\|.*$
或,您希望在|
的第二次和第三次出现之间捕获值,该值以SP
字符串结尾,然后尝试以下正则表达式:
^.*?\s+\S+\s+\|\s+\S+\s+\|\s+([^\\|]*SP)\s+\|.*$
解释:添加了上面的详细说明。
^.*?\s+\S+\s+ ##Matching from starting of value with a lazy match till 1st occurrence of spaces followed by 1 or more non-spaces followed by 1 or more spaces.
\|\s+\S+\s+\| ##Matching |(literal) followed by spaces followed by 1 or more non-spaces followed by spaces with |(literal character) here.
\s+ ##Matching 1 or more spaces occurrences here.
([^\\|]*) ##Creating 1 and only capturing group which has everything till next occurrence of | to get Degree SP value mentioned by OP in samples.
\s+\|.*$ ##Matching 1 or spaces followed by | till last of value/line.
https://stackoverflow.com/questions/69999794
复制相似问题