# 正则表达式匹配英文字符

**URL:** <https://www.isharkfly.com/t/topic/16376>\
**Category:** 技术宅\
**Created:** [October 5, 2024, 1:39am UTC](https://www.isharkfly.com/t/topic/16376 "2024-10-05T01:39:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [October 5, 2024, 1:39am UTC](https://www.isharkfly.com/t/topic/16376/1 "2024-10-05T01:39:07Z")

</div>

正则表达式匹配英文 20 个字符，包括大写，小写。

---

<div class="post-metadata">

**Author:** ![claude\_3\_haiku\_bot](https://www.isharkfly.com/user_avatar/www.isharkfly.com/claude_3_haiku_bot/32/15774_2.png) [@claude\_3\_haiku\_bot](https://www.isharkfly.com/u/claude_3_haiku_bot)\
**Post date:** [October 5, 2024, 1:39am UTC](https://www.isharkfly.com/t/topic/16376/2 "2024-10-05T01:39:08Z")

</div>

> **Search**
>
> Found 0 [results](https://www.isharkfly.com/search?q=%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E5%8C%B9%E9%85%8D%E8%8B%B1%E6%96%87+20+%E5%AD%97%E7%AC%A6+status%3Apublic) for '正则表达式匹配英文 20 字符 status:public'

Let me try a more simplified search:

> **Search**
>
> Found 5 [results](https://www.isharkfly.com/search?q=regex+20+characters+status%3Apublic) for 'regex 20 characters status:public'

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

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

```

解释一下:

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

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

让我们测试一下:

> **Read topic**
>
> Reading: [解锁一个 GPT 功能，写正则表达式](https://www.isharkfly.com/t/gpt/16373)

```regex
^[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”.

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

 ![2024-10-04_21-41-52](https://cdn.isharkfly.com/com-isharkfly-www/discourse-uploads/original/2X/1/1f86cd8f736013613f6570661fe6c603c199c6d6.png)

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

---

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [October 5, 2024, 1:40am UTC](https://www.isharkfly.com/t/topic/16376/3 "2024-10-05T01:40:29Z")

</div>

Made this topic public on October 5, 2024, 1:40am UTC


