使用正则表达式查找控制字符的 XML 字符引用
我需要一些帮助来找出控制字符(十进制或十六进制)的 XML 字符引用的正则表达式。
这些序列如下所示:
�




换句话说,它们是一个 & 符号,后跟一个井号,后跟一个可选的“x”以表示十六进制模式,后跟 1 到 4 个十进制(或十六进制)数字,最后跟一个分号。
我特别尝试识别那些包含(包含)十进制 0 到 31 或十六进制 0 到 1F 的数字的序列。
有人能找出这个的正则表达式吗?
I need some help figuring out the regex for XML character references to control characters, in decimal or hex.
These sequences look like the following:
In other words, they are an ampersand, followed by a pound, followed by an optional 'x' to denote hexadecimal mode, followed by 1 to 4 decimal (or hexadecimal) digits, followed by a semicolon.
I'm specifically trying to identify those sequences where they contain (inclusive) numbers from decimal 0 to 31, or hexadecimal 0 to 1F.
Can anyone figure out the regex for this??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 零宽度先行断言 来限制位数,您可以编写模式的其余部分,无需担心长度限制。试试这个:
说明:
此模式允许在
x
后添加前导零,但(?=x?[0-9A-Fa-f]{1,4})
部分防止它们在x
之前发生。If you use a zero-width lookahead assertion to restrict the number of digits, you can write the rest of the pattern without worrying about the length restriction. Try this:
Explanation:
This pattern allows leading zeroes after the
x
, but the(?=x?[0-9A-Fa-f]{1,4})
part prevents them from occurring before anx
.它不是最优雅的,但它应该可以工作。
在 RegexBuddy 中验证。
It's not the most elegant, but it should work.
Verified in RegexBuddy.
我认为以下应该有效:
这是一个红宝石:
http://www.rubular.com/r/VEYx25Fdpj
I think the following should work:
Here is a Rubular:
http://www.rubular.com/r/VEYx25Fdpj