的幫助下,我有以下內容的txt文件:閱讀單個或兩個來自文件的話用正則表達式
one two, three, four five, six seven, eight, nine, ten
你能不能幫我寫讀一兩句話是正確的正則表達式(以空格)?
需要的是:
stroke[0] = "one two",
stroke[1] = "three",
stroke[2] = "four five",
stroke[3] = "six seven",
stroke[4] = "eight",
...
我的代碼:
Scanner sc = new Scanner(getResources().openRawResource(R.raw.skills));
while (sc.hasNext()) {
stroke[n] += sc.next("\\w|\\w\\s\\w");
n++;
}
如何在逗號分割然後清理尾隨空格?另外,你需要在你的正則表達式中使用量詞。 '\\ w'匹配單個字符,而不是單詞。 – Jerry