I have the following string:
3#White House, District Of Columbia, United States#US#USDC#DC001#38.8951#-77.0364#531871#382
as you can see, the s
You may use a regex like ^(?:[^#]*#){N}([^#]*)
where N
is the number of your required substring minus 1. To get US
, which is the third value, you may use
^(?:[^#]*#){2}([^#]*)
See the regex demo
Details
^
- start of string(?:[^#]*#){2}
- two sequences of
[^#]*
- any zero or more chars other than #
#
- a #
char([^#]*)
- Capturing group 1: any zero or more chars other than #
.