当前位置:  开发笔记 > 编程语言 > 正文

帮助正则表达式模式

如何解决《帮助正则表达式模式》经验,为你挑选了1个好方法。

我有一个txt文件,每行都有一组随机字符串,我只需要选择只包含字符的行:1234567890qwertyuiopasdfghjklzxcvbnm -._〜

我正在逐行阅读并通过char验证char,我不认为这是最好的方法,我认为RegEx将是完美的.

那么有人可以帮助解决这个问题吗?

谢谢!



1> rampion..:
 /^[-0-9a-z._~]*$/

 ^       :: matches the start of a string/start of a line
 [       :: start of a character class, means match any one of the contained characters
 -       :: dash has a special meaning in character classes, so to avoid having it interpreted for its special meaning, list it first
 0-9     :: shorthand for 0123456789 in a character class
 a-z     :: shorthand for abcdefghijklmnopqrstuvwxyz in a character class
 ._~     :: means exactly these characters in a character class
 ]       :: end of the character class 
 *       :: match zero or more of the previous atom (in this case, the character class)
 $       :: matches the end of a string/end of a line

推荐阅读
喜生-Da
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有