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

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

java - regex to match substring after nth occurence of pipe character

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

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...