regex to match substring after nth occurence of pipe character

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

You can use this.Replace by $1<anything>.See demo.

https://regex101.com/r/tP7qE7/4

This here captures from start of string to | and then captures 3 such groups and stores it in $1.The next part of string till | is what you want.Now you can replace it with anything by $1<textyouwant>.


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

Tags:

Java

Regex