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

Regular expression to find words that begin and end with

Good evening, (sorry for my English is not my native language) I’d like to find words in HTML text.
I don’t get what I want and I ask for help. Sample text:


<div class="text-slate-500 text-white text-5xl bg-white bg-slate-600 bg-red/5 ....."> </div>

I should like to find only the words that begin with bg- or text- and ends with 0

This is the best result I’ve been able to get,
but what’s missing to find final 0?

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

\b(bg-\w*)\b

https://regex101.com/r/Krh5JV/1

\b(text-\w*)\b

https://regex101.com/r/f6v8UL/1

😀 Thanks for help!

I’ve tried several formulas found on the net, I’ve tried to look for other posts here but I couldn’t get anything better.

/(bg.*00)/g

https://regexr.com/7p8fd

🧐

>Solution :

Try \b(bg-[\w-]*0)\b. - isn’t covered by \w and thus your existing patterns would not match bg-slate-600, so we add it in as a possibility in a list with [\w-]. This is the same as [a-zA-Z0-9_-]. Then add 0 to the end of the capture group before the word boundary (\b) for the stipulation that it should match an ending 0.

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