简体   繁体   English

正则表达式的XML-Schema类型正则表达式或模式

[英]XML-Schema type regex or pattern for regex

I want to validate if a certain attribute is a valid regex. 我想验证某个属性是否是有效的正则表达式。 Is there some direct built in type in xml schema maybe xs:regex ? 在xml架构中是否有一些直接内置类型xs:regex

Otherwise is there a regex that defines valid regexes? 否则是否有正则表达式定义有效的正则表达式?

There is, by definition, no regex that can validate regular expressions. 根据定义,没有可以验证正则表达式的正则表达式。

Regular expressions can match regular languages, they are not themselves a regular language. 正则表达式可以匹配常规语言,它们本身不是常规语言。 Much like there can be no regular expression to validate HTML or JavaScript. 就像没有正则表达式来验证HTML或JavaScript一样。

To find out if a string is a legal regular expression, it's easiest to try and create a regex object from it. 要确定字符串是否是合法的正则表达式,最简单的方法是尝试从中创建一个正则表达式对象。 In XSD itself this is impossible, so you'd need the help of an external tool. 在XSD中,这是不可能的,因此您需要外部工具的帮助。

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

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