请问怎么区分
hello word
和
"hello word";
这两个对应的正则是什么
我例子没举好,是这样的 要怎么区分 “字母(可能有空格,下划线,汉字)" 和 没有引号的 字母(可能有空格,下划线,汉字)
好吧,是要怎么区分下面这两个字符串,我试了caozhy的方法好像有点问题
// String line = "\"string\": Hello World,";
String line = "\"string\": \"Hello World\",";
Matcher m = Pattern.compile("\"(.*)\"*\:\s?\"\w+\"\s?,?").matcher(line);
// Matcher m = Pattern.compile("\"(.*)\"*\:\s?\w+\s?,?").matcher(line);
System.out.println(m.matches());
m.reset();
while (m.find()) {
System.out.println(m.group());
}
\w+
\"\w+\"
hello\sword
\"hello\sword\";
一个有引号,一个没引号,至于如何区分?这不需要正则就能区分……
\w+ 匹配 hello world; \"\w+\" 可以匹配 “hello world”。
\w+ : 匹配字母或数字或下划线或汉字 >=1 个
可以看看http://blog.csdn.net/u011845742/article/details/45223147
\"\w+\" 可以匹配 “hello world”。
\w+ 匹配 hello world;