Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would I use regular expression to match a word with at least 5 characters with 's' as the last one?

I’m trying to use regex to match: a word that’s at least 5 characters long and ends with an ‘s’, but the ‘s’ is included in the 5 characters. Say for example, I have the following words:

hexes pixies major prairies caveman zipfiles oxes

I tried doing ([a-z]s?){5,}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The pattern ([a-z]s?){5,} repeats 5 or more times a character in the range a-z followed by an optional s char

If you only want to match characters a-z and "words" are determined by word boundaries \b, you can match 4 or more times the range a-z and end the match with an s char

\b[a-z]{4,}s\b

Regex demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading