gpt4 book ai didi

java - 将字典转换为sqlite数据库

转载 作者:行者123 更新时间:2023-12-01 14:50:16 24 4
gpt4 key购买 nike

我有这种格式的字典

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

我想在 sqlite 数据库表中将其转换为 5 列。尝试使用Regex获得解决方案没有成功。

编辑:

我想要像这样的输出

制 制 [A A zhi4] /to split the bill/to go Dutch/



[A A zhi4]
/to split the bill
/to go Dutch/

任何帮助将不胜感激...

最佳答案

一个可能的正则表达式(每行使用)可能是

(\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 )。

关于java - 将字典转换为sqlite数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14955495/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com