我有这种格式的字典
Traditional Simplified [pin1 yin1] /English equivalent 1/equivalent 2/
^1 ^2 ^3 ^4 ^5
例如
制 制 [A A zhi4] /to split the bill/to go Dutch/
^1 ^2 ^3 ^4 ^5
T字帳 T字帐 [T zi4 zhang4] /T-account (accounting)/xyz abc
^1 ^2 ^3 ^4 ^5
我想用5列在sqlite数据库表中转换这一点。试图通过Regex获得解决方案没有成功。
编辑:
我想要输出像
制 制 [A A zhi4] /to split the bill/to go Dutch/
制
制
[A A zhi4]
/to split the bill
/to go Dutch/
任何帮助都将不胜感激..。
发布于 2013-02-19 11:05:45
一种可能的正则表达式(每行使用)可以是
(\S+)\s+(\S+)\s+\[([^\[\]]*)\]\s*/([^/]*)/([^/]*)
在Java中:
Pattern regex = Pattern.compile(
"(\\S+) # one or more non-whitespace characters -> group 1\n" +
"\\s+ # one or more whitespace characters\n" +
"(\\S+) # one or more non-whitespace characters -> group 2\n" +
"\\s+ # one or more whitespace characters\n" +
"\\[ # [\n" +
"([^\\[\\]]*) # anything except [] -> group 3\n" +
"\\] # ]\n" +
"\\s*/ # optional whitespace, then /\n" +
"([^/]*) # anything except / -> group 4\n" +
"/ # /\n" +
"([^/]*) # anything except / -> group 5",
Pattern.COMMENTS);
匹配之后,这五个组将位于Matcher
对象的.group(n)
(用于1 <= n <= 5
)中。
https://stackoverflow.com/questions/14955495
复制相似问题