正则表达式匹配特定位置的字符 [英] regex to match character in specific position

查看:31
本文介绍了正则表达式匹配特定位置的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要想出一个正则表达式来仅在给定文本的位置 9 上查找字母 A、F 或 E.我对正则表达式真的很陌生,做了一些搜索,但找不到任何类似的响应.到目前为止我所拥有的是:

I need to come up with a regex to look for only letters A, F or E on the position 9 of a given text. I am really new with regex, did some searching and couldn't find any similar response. what i have so far is:

/^.{9}A/

此命令似乎可以在空格 9 上找到字母 A,但是如何将其他 2 个字母添加到正则表达式中?

This command seems to work to find letter A on the space nine, but how can I add the other 2 letters to the regex?

推荐答案

您说您正在寻找 C、F 或 E,但在您的示例中寻找 A,因此请在括号中包含您想要匹配的任何其他字母,但你要找的是:

You say you're looking for C, F or E but looking for A in your example, so please include in the brackets any other letters you want to match, but what you're looking for is:

/^.{8}[CFE]/

它应该是 {8} 而不是 {9} 因为按照你的方式,它会匹配前 9 个字符,然后匹配你的字母位置10.

It should be {8} rather than {9} because the way you had it, it'll match the first 9 characters and then match your letter in position 10.

这篇关于正则表达式匹配特定位置的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆