英文:
Notepad++ regex - find or remove specific numbers
问题
I would like to remove specific numbers from a text file, the list of the numbers are in order from 1 to 192061.
我想从文本文件中删除特定的数字,这些数字按顺序从1到192061排列。
I need to remove a group of numbers, some examples: "61186","95492","158740","151276","92709"
我需要删除一组数字,一些示例:"61186","95492","158740","151276","92709"
And my list in total is around of 13k.
我的列表总共大约有13,000个。
I have tried this: (61186)|(95492)|(158740)|(151276)|(92709).
我尝试过这个:(61186)|(95492)|(158740)|(151276)|(92709)。
But in the list I have: 61186 and 161186 and it will not match.
但在列表中,我有61186和161186,它们不匹配。
英文:
I would like to remove specific numbers from a text file, the list of the numbers are in order from 1 to 192061.
I need to remove a group of numbers, some exemples : "61186","95492","158740","151276","92709"
And my list in total is around of 13k.
I have tried this : (61186)|(95492)|(158740)|(151276)|(92709).
But in the list I have : 61186 and 161186 and it will not match.
答案1
得分: 1
A simple number range generated regex for 1 - 192061 would be:
(?<!\d)(?:[1-9]\d{0,4}|1[0-8]\d{4}|19[01]\d{3}|1920[0-5]\d|19206[01])(?!\d)
It's doubtful you should do it without the look ahead/behind assertions,
but the regex could be rearranged like this:
1[0-8]\d{4}|19[01]\d{3}|1920[0-5]\d|19206[01]|[1-9]\d{0,4}
英文:
A simple number range generated regex for 1 - 192061 would be:
(?<!\d)(?:[1-9]\d{0,4}|1[0-8]\d{4}|19[01]\d{3}|1920[0-5]\d|19206[01])(?!\d)
https://regex101.com/r/YL4GS3/1
It's doubt full you should do it without the look ahead/behind assertions,
but the regex could be re-arrange like this :
1[0-8]\d{4}|19[01]\d{3}|1920[0-5]\d|19206[01]|[1-9]\d{0,4}
答案2
得分: 1
只需使用 ^
和 $
锚点来匹配行的开头和结尾,并在所有替代项周围使用捕获组,而不是每个替代项都使用一个,例如:
^(61186|95492|158740|151276|92709|438)$
英文:
Simply use ^
and $
anchors to match start/end of the line and use capture group around all the alternatives rather than for each one, e.g.:
^(61186|95492|158740|151276|92709|438)$
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论