是否可以检测文本中的编程语言源代码(主要是 Java 和 C#)?
比如我想知道本文中有没有源代码部分。
.. text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
public static Person createInstance() { return new Person();}
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text ..
我已经搜索了一段时间,但找不到任何东西。
Python 的解决方案会很棒。
问候。
最佳答案
周围有一些语法高亮器(pygments,google-code-prettify),它们解决了代码检测和分类问题。研究他们的来源可能会给人留下深刻印象。
(现在我再次查看了 pygments - 我不知道他们是否可以自动检测编程语言。但是 google-code-prettify 绝对可以做到)
关于python - 如何检测文本中的源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179439/