Issue
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?
\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
🧐
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
.
Answered By - Wongjn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.