我有这种形式的字符串列表
1:nlcbjduy14 <- I want regex to find this one
2:Peoples123 <- I don't want regex to find this one, as it has 3 digits.
3:sqourzyr17 <- I want regex to find this one
4:rdmaszgr94 <- I want regex to find this one
5:tnwiudic22 <- I want regex to find this one
6:zfcxmkrs21 <- I want regex to find this one
7:xrwhsgno55 <- I want regex to find this one
8:modtwtrr06 <- I want regex to find this one
9:People123 <- I don't want regex to find this one, as it is isn't 10 chars long and it consists of 3 digits.
10:aetmyqqh52 <- I want regex to find this one
11:Howtocodelikeapro12 <- I don't want regex to find this one, as it is isn't 10 chars long
12:netphvib58 <- I want regex to find this one
13:uwyiqhoj29 <- I want regex to find this one
14:RegexJustiIsntDoingItForMe
15:qyeiaecj27 <- I want regex to find this one
16:buttercake <- I don't want regex to find this one, as it doesn't end with 2 digits.
17:bcyiyjdm23 <- I want regex to find this one
18:Differings <- I don't want regex to find this one, as it doesn't end with 2 digits.
我要寻找的是某种正则表达式来替换所有以max结尾的10个字符的字符串。 2位数字。
替换了这些字符串之后,它看起来像这样:
1:REPLACED
2:Peoples123
3:REPLACED
4:REPLACED
5:REPLACED
6:REPLACED
7:REPLACED
8:REPLACED
9:People123
10:REPLACED
11:Howtocodelikeapro12
12:REPLACED
13:REPLACED
14:RegexJustiIsntDoingItForMe
15:REPLACED
16:buttercake
17:REPLACED
18:Differings
有人可以给我一个可以使用的正则表达式示例吗? 我在Stackoverflow上找不到其他任何(可理解的)问题,因为我对正则表达式不是很熟悉。我正在尝试在Notepad ++中匹配这些,而不是在任何编程语言中匹配。
谢谢!
答案 0 :(得分:2)
好吧,在不知道您使用的是哪种口味的情况下(如果是PHP或python,例如e.t.c),给您一个答案要困难一点,但是尝试一下:
\d+:\D{8}\d{2}
我强烈建议您花些时间研究Regex,因为它是功能强大的工具。
如果您想了解此正则表达式并学到更多知识,请转到here
答案 1 :(得分:1)
尝试:仅匹配#:
之后的文本
(?<=\:)\D{8}\d{2}\b
(?<=\:)
-:
字符的正面表情\D{8}
-恰好8个数字\d{2}
-精确到2位数字\b
-单词边界(单词结尾)使用它,您可以维护您的电话号码,但可以替换用户名
答案 2 :(得分:0)
我认为此RegEx有效:
:\D{8}\d{2}\D
它由:组成,因为它是字符串的开头。然后,我们有8个非数字字符,2个数字字符和一些非数字字符,以防止数字过长。它遵循PCRE标准,因此应与您的编辑器Notepad ++一起使用。
答案 3 :(得分:0)
您可以尝试以下操作:Link to Regex101
\W([A-Za-z]{8}\d{2})\W
说明
\W
-匹配既不是字母数字也不是下划线的任何字符\W(...)\W
-括号中的组是我们想要的东西。它是一个既不包含字母数字也不包含下划线的字符串。我们称它为“单词”。[A-Za-z]{8}
-连续的字符串,精确长度为8。\d{2}
-恰好是两个连续数字。我不确定Notepad ++,但是在大多数情况下,您可以使用$1
来获得第一组。第零组将是整个比赛。