regex - 检查我的用户名后的第一个数字是否大于 500
问题描述
我正在尝试检查我的用户名后的第一个数字是否大于 500。我尝试搜索的 XML 文件的结构如下:
<username>Joker876</username>
<text xml:space="preserve" number="524">
我想出了一个正确过滤数字的脚本,但如果数字小于 500,它会搜索下一个。我想这样做,如果数字与模式不匹配,它不会搜索匹配的数字,而是搜索我的用户名。例子:
<username>Joker876</username>
<text xml:space="preserve" number="524"> <-- this should match
<username>Username here</username>
<text xml:space="preserve" number="524"> <-- this should not match
<username>Joker876</username>
<text xml:space="preserve" number="50"> <-- this should not match and should not match the number
<username>Joker876</username> two lines below
<text xml:space="preserve" number="524">
这是我的代码:
<username>Joker876</username>.*?number="([5-9]\d\d|[1-9]\d{3,})"
此外,我将在 Notepad++ 查找功能中使用此正则表达式代码。
解决方案
您可以使用
<username>Joker876</username>\R<[^<>]*number="([5-9]\d\d|[1-9]\d{3,})">
查看正则表达式演示
细节
<username>Joker876</username>
- 文字文本\R
- 任何换行序列<
- 一个<
字符[^<>]*
- 0+ 字符除了<
和>
number="
- 文字文本([5-9]\d\d|[1-9]\d{3,})
-5
,6
,7
,8
或9
后跟任意两位数字或非零数字后跟任意三位或更多数字">
- 文字文本
推荐阅读
- python - 找不到满足要求 tensorflow 的版本 - 在 docker 内
- mysql - 当 WHERE 子句中的一个字段为空时,MySQL 数据库是否使用复合索引?
- html - 如何显示完整图像而不是方形图像的部分图像
- sql - SQL根据列值条件返回行
- typescript - 如何为打字稿枚举类型 {[key]: value } 生成文档?
- ffmpeg - FFMPEG 将 m3u8 重新流式传输到 Youtube 在第一段之后不断返回“无法更新具有正确持续时间和文件大小的标头”
- r - R中按组月的平均温度
- swiftui - 删除所选项目时 SwiftUI 列表崩溃
- python - 如何标记按熊猫箱线图分组的?
- wordpress - 自动生成的页面文件