You can use String#replaceAll that has support for regex like this:
String newstr = str.replaceAll("(&firstString=)[^&]*(&endString=)", "$1foo$2");
More Related Contents:
- Regular Expression for name
- Understanding Java regular expression [duplicate]
- password validation with regex in java
- java Dangling meta character ‘+’ [closed]
- Regex doesn’t work in String.matches()
- How to extract a substring using regex
- Regex to match only commas not in parentheses?
- Why does String.split need pipe delimiter to be escaped?
- Java Regex Replace with Capturing Group
- How to use regex in String.contains() method in Java
- Regex exactly n OR m times
- Detect and extract url from a string?
- What is the regex for “Any positive integer, excluding 0”
- Extract string between two strings in java
- Is Java Regex Thread Safe?
- How to extract parameters from a given url
- Passing parameters to action through ModelDriven in Struts 2
- How to use java regex to match a line
- How to remove the backslash in string using regex in Java?
- Regex pattern including all special characters
- Java; String replace (school project)?
- Remove all non-“word characters” from a String in Java, leaving accented characters?
- java.util.regex.PatternSyntaxException: Dangling meta character ‘+’ near index 0 +
- How to match repeated patterns?
- How to escape a square bracket for Pattern compilation?
- Regex to get first number in string with other characters
- How does this Java regex detect palindromes?
- Parse Date from String in this format : dd/MM/yyyy [to dd/MM/yyyy]
- How can I perform a partial match with java.util.regex.*?
- Java replace all square brackets in a string