python - 如何检测文本中的源代码?

标签 python

是否可以检测文本中的编程语言源代码(主要是 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 的解决方案会很棒。

问候。

最佳答案

周围有一些语法高亮器(pygmentsgoogle-code-prettify),它们解决了代码检测和分类问题。研究他们的来源可能会给人留下深刻印象。

(现在我再次查看了 pygments - 我不知道他们是否可以自动检测编程语言。但是 google-code-prettify 绝对可以做到)

关于python - 如何检测文本中的源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179439/

相关文章:

python - .strip 在 python 中不起作用

python - 在 Python 中将列表转换为集合!我究竟做错了什么?

REST请求中基于python证书的身份验证

python - 与Python中的子图共享X轴并同时更改大小

python 这条线在做什么?

python - 在 linux 中设置 python 脚本的日期/时间

Python turtle 模块导致 OS X 崩溃

Python:重写子类中的静态成员

python - 二进制 -> UTF-8 -> 字符串

python - 使用 SQLAlchemy,如何在类中创建一个字段,该字段是该类的其他实例的列表?