在第n个管道字符出现后匹配子字符串的正则表达式 [英] regex to match substring after nth occurence of pipe character

查看:98
本文介绍了在第n个管道字符出现后匹配子字符串的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为下面的示例文本构建一个正则表达式,我需要替换粗体文本。到目前为止,我可以实现这么多
((\ |))。*(\ |)这是选择第一个和最后一个点之间的整个字符串焦炭。我必然会使用apache或java正则表达式。

i am trying to build one regex expression for the below sample text in which i need to replace the bold text. So far i could achieve this much ((\|)).*(\|) which is selecting the whole string between the first and last pip char. i am bound to use apache or java regex.

示例字符串:管道之间的文本长度可能会有所不同

Sample String: where text length between pipes may vary

1.1|ProvCM|111111111111|**10.15.194.25**|10.100.10.3|10.100.10.1|docsis3.0


推荐答案

要在 nth 管道出现后匹配部分,您可以使用此正则表达式:

To match part after nth occurrence of pipe you can use this regex:

/^(?:[^|]*\|){3}([^|]*)/

这里n = 3

它会匹配匹配组#1中的 10.15.194.25

It will match 10.15.194.25 in matched group #1

RegEx演示

这篇关于在第n个管道字符出现后匹配子字符串的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆