简体   繁体   English

Python Regex匹配多行Java注释

[英]Python Regex match multiline Java annotation

I am trying to take advantage of JAXB code generation from a XML Schema to use in an Android project through SimpleXML library, which uses another type of Assertion than JAXB (I do not want to include a 9MB lib tu support JAXB in my Android project). 我正在尝试利用XML模式生成JAXB代码,以通过SimpleXML库在Android项目中使用该库,该库使用的是JAXB之外的另一种断言类型(我不想在我的Android项目中包含9MB的lib tu支持JAXB) 。 See question previously asked 查看先前询问的问题

Basically, I am writing a small Python script to perform the required changes on each Java file generated through the xcj tool, and so far it is working for import deletion/modification, simple line annotation, and also the annotation for which a List @XMLElement needs to be converted to an @ElementList one. 基本上,我正在编写一个小的Python脚本,以对通过xcj工具生成的每个Java文件执行所需的更改,到目前为止,它可以用于导入删除/修改,简单的行注释以及List @XMLElement的注释需要转换为一个@ElementList。

The only issue I am facing right now is for removing annotations on several lines, such as @XMLSeeAlso or @XMLType like the following 我现在面临的唯一问题是要删除多行注释,例如@XMLSeeAlso或@XMLType,如下所示

@XmlType(name = "AnimatedPictureType", propOrder = {
    "resources",
    "animation",
    "caption"
})

or 要么

@XmlSeeAlso({
    BackgroundRGBColorType.class,
    ForegroundRGBColorType.class
})

I tried different strategies using either Multineline, DotAll, or both, but without any success. 我尝试使用Multineline,DotAll或同时使用两者的不同策略,但均未成功。 I am new to "advanced" regex usage as well as Python so I am probably missing something silly. 我是“高级”正则表达式用法以及Python的新手,所以我可能缺少一些愚蠢的东西。

For my simple XSD processing that is the only step I cannot get running to achieve a fully automated script using xcj and then automatically convert JAXB annotations into Simple XML ones. 对于我的简单XSD处理,这是唯一的步骤,我无法运行以使用xcj实现全自动脚本,然后将JAXB注释自动转换为Simple XML注释。

Thank you in advance for your help. 预先感谢您的帮助。

@Xml.*\\}\\) with dotall enabled should as far as i know match any annotation starting with @Xml and ending with "})", even when it is multiline. 据我所知,启用dotall的@Xml.*\\}\\)应该与以@Xml开头并以“})结尾的任何注释匹配,即使它是多行。

For a good view of what your regex actually matches you could always test your regular expressions at websites like https://pythex.org/ 要了解正则表达式实际匹配的内容,您可以随时在https://pythex.org/等网站上测试正则表达式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM