提取第二个下划线和第三个下划线或空格之间的单词 [英] extract word between 2nd underscore and 3rd underscore or space
本文介绍了提取第二个下划线和第三个下划线或空格之间的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提取第二个 & 之后的单词第三个下划线 (_
) 或第二个下划线 & 之间的单词空间.
i want to extract the word after the 2nd & 3rd underscore (_
) or the word between the 2nd underscore & space.
我的示例数据是:
COL_POS_CJMA_CA_03.09.17
COL_DPU_CJER_CK_03.08.17
COL_POS_CJNE CA_03.09.2017
COL_DPU_CJEK CK_03.08.2017
我的结果应该是:
CJMA
CJER
CJNE
CJEK
我已经有了这个_[^_]*_([^_]*)_
我可以提取第一个两个结果.如果有人可以帮我提取第三个&第 4 个结果
I already have this _[^_]*_([^_]*)_
And I could extract the 1st two results.
If any one could help me extract the 3rd & 4th results
表示第三个下划线或空格之间的正则表达式
A regex that says between the 3rd underscore or a space
推荐答案
你可以去
^(?:[^_]+_){2}([^_ ]+)
请参阅 regex101.com 上的演示.<小时>分解,这说:
See a demo on regex101.com.
Broken down, this says:
^ # beginning of string
(?: # non-capturing group
[^_]+ # not _, at least once
_ # _
){2} # repeat the group twice
([^_ ]+) # capture characters not _ or spaces to group 1
... 或者,被_
分割并分析为一个数组,即result[2]
.
... or, split by _
and analyze the result as an array, ie result[2]
.
这篇关于提取第二个下划线和第三个下划线或空格之间的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文