I am trying to write a regex (with very little luck) to capture a string that occurs between two slashes in a specific location within a larger string.
An example source string would be: There will be some text description here followed by the path: /XYZ/String-needed/ABC/ETC
The string-needed will always be between the second and third /
character.
The context of regex for this is within another tool, but it models mostly a java context of regex usage. I know that the /
will need to be escaped \/
but I cannot get the code to find the string between the second and third instance.
You can use following regex :
"^\/[^/]+\/([^/]+)\/"
See demo https://regex101.com/r/jR9rV5/1
[^/]
is a negated character class which match any string except /
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With