如果我有字符串
thisIsSomthing=4891\r\n
thisIsSomthingElse=27398472\r\n
thisIsNumber1=1\r\n
我怎么找到
thisIsNumber1
然后使用正则表达式返回1
答案 0 :(得分:3)
这假设您确实将所发布的内容放在字符串中,而不是放在文件中。当您处理属性时,您应该使用Properties
而不是正则表达式:
String yourString = ...
Properties prop = new Properties();
try {
prop.load(new StringReader(yourString));
String result = prop.getProperty("thisIsNumber1");
System.out.println(result);
} catch (IOException e) {
System.out.println("Error loading properties:");
e.printStackTrace();
}
答案 1 :(得分:1)
/ thisIsNumber1 =(\ d +)。* /
它将在捕获组1中。
答案 2 :(得分:0)
String line="thisIsNumber1=1\r\n";
String temp=line.split("\\r?\\n")[0].split("=")[1];
System.out.println("Value="+temp+"*"); // 1* "*" shows nothing is concatenated after
the character in the output