Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
696 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

Here n=3

It will match 10.15.194.25 in matched group #1

RegEx Demo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...