Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

regex to match character in specific position

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/

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]/

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...