import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^(LTE|RS[A-Z]+)\\s*([^:]+):\\s+(.*?)(?=\\s*$)";
final String string = "AT!GSTATUS?\n"
+ "!GSTATUS: \n"
+ "Current Time: 54902 Mode: ONLINE \n"
+ "System mode: LTE PS state: Attached \n"
+ "EMM state: Registered Normal Service \n"
+ "RRC state: RRC Connected \n"
+ "IMS reg state: No Srv \n\n"
+ "PCC: \n"
+ "LTE band: B28 \n"
+ "LTE bw: 10 MHz \n"
+ "LTE Rx chan: 9260\n"
+ "LTE Tx chan: 27260\n"
+ "RSSI (dBm): -48.0\n"
+ "RSRP (dBm): -74.5\n"
+ "RSRQ (dB): -12.2\n"
+ "RSSNR (dB): 12\n"
+ "Tx Power (dBm): \n"
+ "LTE Cell ID: 23198257\n"
+ "Physical Cell ID: 307\n"
+ "TAC: 57506\n\n"
+ "SCC1: \n"
+ "LTE band: B1 \n"
+ "LTE bw: 15 MHz \n"
+ "LTE Rx chan: 275\n"
+ "RSSI (dBm): -59.5\n"
+ "RSRP (dBm): -87.5\n"
+ "RSRQ (dB): -9.2\n"
+ "Physical Cell ID: 412\n\n\n"
+ "OK";
final String subst = "";
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