Код: Выделить всё
package com.example.ticket_query;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* "station_train_code": "D29(天津西-齐齐哈尔南)", \(.*-.*\)
*/
class TicketQueryApplicationTest {
Pattern pattern = Pattern.compile(".*station_train_code.*");
Pattern stationNamePattern = Pattern.compile("\\(.*-.*\\)");
@DisplayName(value = "获取所有的车站名称")
@Test
void getStationName() {
String s = "11(adfa-2342)df";
Matcher stationNames = stationNamePattern.matcher(s);
if (stationNames.matches()) {
System.out.println(s);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... using-java