我希望正则表达式在两个字符之间找到字符串,但仅从开始定界符到第一次出现结束定界符
我想从以下格式的行中提取故事
所以我只想提取: {some_text_here}
为此,我使用以下正则表达式:
和Java代码:
public static void main(String[] args) throws IOException {
String regexString = "";
String filePath = "C:\\Desktop\\temp\\test.txt";
Pattern p = Pattern.compile(regexString);
Matcher m;
try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
String line;
while ((line = br.readLine()) != null) {
m = p.matcher(line);
if (m.find()) {
System.out.println(m.group(1));
}
}
}
}
这个正则表达式通常可以正常工作,但是如果该行是:
运行代码还会过滤My name is Nick" extraStory="something ,我只想确保我得到的My name is Nick
我也想确保在story="My name is Nick"和/>之前之间没有任何信息