自动更正编码正则表达式模式

发布于 2024-12-04 01:50:00 字数 339 浏览 4 评论 0原文

我正在为字符串输入编码构建自动更正。我想构建一个用于编码模式的正则表达式。

例如:

var encoding = "utd-8";
Correct c = new Correct(encoding);
var c.Correct();

输出为utf-8。 我承担了大部分工作(并使用了一些伟大的人编写的一些开源代码,他们写了漂亮的东西)。有人可以帮忙吗?

更新

我最终需要的是正确编码的正则表达式模式。 用户输入编码名称iso-8859-1并检查其是否有效。

I am building auto correct for string input encoding. And I want to build a regex for encoding pattern.

For example:

var encoding = "utd-8";
Correct c = new Correct(encoding);
var c.Correct();

And the output is utf-8.
I have most of the work (and using some open source coding from some great people that wrote beautiful stuff). Can some one help please?

UPDATE

What I need in the end is the regex pattern for the right encoding.
The user input a encoding name iso-8859-1 and it check if its valid.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

衣神在巴黎 2024-12-11 01:50:00

在弄清楚如何解决问题之前,您不应该决定使用哪种技术;正则表达式真的有必要吗?

如果我正确理解你的问题,你想检查输入字符串是否看起来很像支持的编码之一。在编写一行代码之前,您必须弄清楚:

  • 您支持哪些编码?您是否支持别名(UTF-16Unicode 相同)?
  • 输入字符串允许与所选编码(utd-8、utd-9、utd9、td9、9)有多少不同?
  • 给定输入字符串“utf-36”,输出是 UTF-16 还是 UTF-32

也许您可以看一下其中一种字符串距离算法(例如,http://en.wikipedia。 org/wiki/Levenshtein_distance)以获取有关该主题的灵感。 “另请参阅”部分中有大量链接。

You shouldn't decide on which technology to use before you have figured out how to solve the problem; are Regular Expressions really necessary?

If I understand your question correctly, you want to check whether the input string looks alot like one of the supported encodings. Before writing a single line of code, you'll have to figure out:

  • Which encodings are you supporting? Are you supporting aliases (UTF-16 is the same as Unicode)?
  • How much is the input string allowed to be different from the chosen encoding (utd-8, utd-9, utd9, td9, 9)?
  • Given the input string "utf-36", would the output be UTF-16 or UTF-32?

Perhaps you can take a look at one of the string distance algorithms (for example, http://en.wikipedia.org/wiki/Levenshtein_distance) for inspiration on the subject. There are a ton of links in the "see also" section there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文