c# - 帮助正则表达式模式

标签 c# regex

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

我正在逐行阅读并逐个字符验证,我认为这不是最好的方法,而且我认为 RegEx 是完美的。

那么有人可以为此提供模式帮助吗?

谢谢!

最佳答案

 /^[-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

关于c# - 帮助正则表达式模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/703600/

相关文章:

regex - Perl正则表达式删除字符串中重复的连续子字符串

RegEx - 在单字符之前匹配单词,而不是双字符?

regex - 为什么在 htaccess 正则表达式中使用双斜线点(即 :\\. )?

C# 在桌面上定位窗口

c# - 使用 'ProjectServiceExtension' 用于 NaCl 的 MonoDevelop 插件

java - 使用正则表达式查找字符串中不包含特定字母的所有单词

regex - 如何从字符串中提取信息

javascript - 如何在C#中网页从一个页面导航到另一个页面时执行代码

c# - 如何使用 openURL() 读取在 safari 中打开的 html 文件

c# - 如何在代码后面检查端口当前是否与 IIS7 (webSite) 一起使用?