regex - XML 模式的正则表达式
问题描述
我有这个 xml 内容,id 值从 1 到 193。
<member lang="en" id="UN193">
<name>Zimbabwe</name>
<admissionYear>1980</admissionYear>
<population year="2019">14645468</population>
<continent>Africa</continent>
<officialLangInfo>
<language script="Latin" family="Indo-European">English</language>
<language script="Latin" family="Niger–Congo">Chewa</language>
<language script="Latin" family="Niger–Congo">Kalanga</language>
<otherLanguage>Chibarwe</otherLanguage>
</officialLangInfo>
</member>
我创建了这个限制,这给了我一个错误验证文件。有什么建议么?非常感谢。
<xs:attribute name="id" use="required">
<xs:simpleType>
<xs:restriction base="xs:ID">
<xs:pattern value="[UN][0-9]{1,3}"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
解决方案
一种可能性是使用to 允许范围内的UN\[0-9]{1,3}
id 。UN0
UN999
如果你想更精确并且只允许从 1 到 193 的 id,你可以尝试类似UN(1[0-9][0-3]|[1-9][0-9]|[1-9])
.
这里的例子。
推荐阅读
- google-apps-script - 在特定下拉区域中进行更改时,向有权访问工作表的人员发送电子邮件
- javascript - 如何加载包含的 HTML 文件 element?
I want to re-use my custom web component. My web pages are primarily defined by HTML files, not Javascript. Is there any viable way to insert my component into my main file using HTML/Javascript/jQuer
- javascript - const 仅在解构时显示为未定义,而不是在重新分配给另一个 const 时
- html - 页眉没有到达边界
- node.js - npm scripts won't execute
- javascript - TypeError:无法读取 ReactJS Jest 测试中未定义的属性“标题”
- vue.js - Vue watcher triggered on creating sibling property
- python - Connect Cloud Run container to Cloud SQL
- ios - AVCapturePhotoCaptureDelegate Error When Capturing Image
- r - R中的条件概率实验