正则表达式匹配英文字符

Search

Found 0 results for '正则表达式匹配英文 20 字符 status:public'

Let me try a more simplified search:

Search

Found 5 results for 'regex 20 characters status:public'

根据搜索结果,看到 honeymoose 分享过一个正则表达式的要求是:
匹配 20 个英文字符(大写、小写都包括)。
那么这个正则表达式可以写成:

^[a-zA-Z]{20}$

解释一下:

  • ^ 表示匹配字符串的开始
  • [a-zA-Z] 表示匹配任意大写或小写英文字母
  • {20} 表示匹配20个字符
  • $ 表示匹配字符串的结束

这个正则表达式能匹配到一个 20 个英文字符的字符串。

让我们测试一下:

Read topic

Reading: 解锁一个 GPT 功能,写正则表达式

^[a-zA-Z]{20}$

This regular expression will match exactly 20 English alphabetical characters, including uppercase and lowercase letters.

Explanation:

  • ^ asserts the start of the string
  • [a-zA-Z] matches any uppercase or lowercase English letter
  • {20} matches the preceding pattern exactly 20 times
  • $ asserts the end of the string

So this regex pattern will match strings like “ABCDEFGHIJKLMNOPQrst” but not “abc123DEF” or “ABCDEFGHIJKLMNOPQ”.

用正则表达式测试了下字符。

以前都比较害怕使用正则表达式,现在有了 GPT,实在是又提高了工作效率。

1 Like