1

I am trying to extract a the substring between the second slash and the first = character. Currently I'm using split to achieve this. How can I use regex to do this?. Thanks in advance.

input - "/test/example=1244 output- example

This is what I'm using currently:

String test= inputString.split("/")[2].split("=")[0];
2

1 Answer 1

1

You could split on a regex alternation of slash or equals:

String test = "/test/example=1244";
String output = test.split("[/=]")[2];
System.out.println(output);

This prints:

example
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.