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

Split words contained in string based on uppercase

I have a string that has no spaces, what marks every single word is the uppercase letter at the beginning of each word, what would be the best way for extracting them?

here’s what i’ve got:

str = "TheseAreAFewWordsAndThis-one-contains-wildcards"

Desired output would be:

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

These
Are
A
Few
Words
And
This-one-contains-wildcards

I don’t need to treat any magical characters as such, they can stay in the string no problems

>Solution :

for wrd in str:gmatch("%u%U*") do print(wrd) end

"%u%U*" is a string pattern that matches a single capital letter followed by any number of non capital letter characters.

Please read https://www.lua.org/manual/5.4/manual.html#6.4.1

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