import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^m=[a-zA-Z]*) ([0-9]{0,5})";
final String string = "v=0\n"
+ "o=bob 2808844564 2808844564 IN IP4 host.biloxi.example.com\n"
+ "s=\n"
+ "c=IN IP4 host.biloxi.example.com\n"
+ "t=0 0\n"
+ "m=audio 49174 RTP/AVP 0\n"
+ "a=rtpmap:0 PCMU/8000\n"
+ "m=video 49170 RTP/AVP 32\n"
+ "a=rtpmap:32 MPV/90000\n\n\n"
+ "m=audio 49170 RTP/AVP 0\n"
+ "a=rtcp:53020\n\n"
+ "m=audio 49170 RTP/AVP 0\n"
+ "a=rtcp:53020 IN IP4 126.16.64.4\n\n"
+ "m=audio 49170 RTP/AVP 0\n"
+ "a=rtcp:53020 IN IP6 2001:2345:6789:ABCD:EF01:2345:6789:ABCD";
final String subst = "$1 5060";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html