首页 > 解决方案 > 检查我的用户名后的第一个数字是否大于 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++ 查找功能中使用此正则表达式代码。

标签: regex

解决方案


您可以使用

<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,89后跟任意两位数字或非零数字后跟任意三位或更多数字
  • "> - 文字文本

推荐阅读