1

I want to find and replace a substring beginning with string 'sps.jsp' and ending with substring 'FILE_ARRAY_INDEX=12'.

Following is my string content

beginning with strings............[sps.jsp]..anything between.. [FILE_ARRAY_INDEX=12] ending with some strings....

Below is my code

 Pattern r = Pattern.compile("sps.jsp[\\s\\S]*?FILE_ARRAY_INDEX=12");
 Matcher m = r.matcher(InputStr);
 if (m.find( )) 
 {
   System.out.println("Found value: " + m.group() );
 }

I'm not able to get my pattern and replace it with a new string.

0

1 Answer 1

1

All you need is to String::replaceAll with this regex sps.jsp(.*?)FILE_ARRAY_INDEX=12

String inputStr = "....";//your input
inputStr = inputStr.replaceAll("sps.jsp(.*?)FILE_ARRAY_INDEX=12", "[some string]");

Outputs

beginning with strings............[some string] ending with some strings....
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.