0
Regex matching string containing specific letters
I have a regular expression that'll match all strings containing the letters 'r' and 'h': /(.*h.*r.*|.*r.*h.*)/ The problem with this method is that it gets very long pretty quickly. If it was 3 letters it would look like this: /(.*h.*r.*k.*|.*h.*k.*r.*|.*r.*k.*h.*|.*r.*h.*k.*|.*k.*h.*r.*|.*k.*r.*h.*)/ Isn't there a simpler way to do this? It just has to match a string containing 1 or more of all letters
3 Respuestas
+ 1
r'\w*[hrk]+\w*'
=> any amount (including 0) of other letters, at least one h, r, or k and 0 or any amount of other letters again
0
Anna where can we learn more about regular expressions
0
Milan Adhikari You can try Sololearn's tutorial:
https://www.sololearn.com/learn/9704/?ref=app
There are good resources on the web, too