Clear Filters
Clear Filters

regexp to capture only certain length of characters

4 views (last 30 days)
Hi, I'm trying to capture words with 4 characters only. A word consists or alphanumeric characters.(no symbols of white space)
str4='4-44g 4541 75872 a4cd stuvw';
I'm expecting 4541 a4cd as the correct answer. However my code outputs stuv & 7587 in addition. How can I correct this

Answers (2)

Rashmil Dahanayake
Rashmil Dahanayake on 7 Aug 2014
This could be the solution
str4='4-44g 4541 75872 abcd stuvw';

Azzi Abdelmalek
Azzi Abdelmalek on 7 Aug 2014
str4='4-44g 4541 75872 a4cd stuvw';
regexpi([' ' str4 ' '],'(?<=[^0-9,a-z])[0-9,a-z]{4}(?=[^0-9,a-z])','match')



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!