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
339 views
in Technique[技术] by (71.8m points)

regex - How to check if three specific letters exist in word using regular expression?

For example I have a word: telephone. I need to check by regular expression existing of letters t,l,p.

Not separately t or l or p, no ... all at once. If there is t,l but not p in the word then it means FALSE. The main aim to show that in this word all three letters in use.

I just need to get approvement of existence of theese three letters in one word from regular expression using preg_match in php

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

(?=S*t)(?=S*l)(?=S*p).+

This regex will match any word containing all three letters t, l and p, regardless of the order.

Basically, you need to add (?=S*x) for each letter you want the word to contain, where x is the letter you want.

Demo here


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

...