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
🧐
3
Answers
Try
b(bg-[w-]*0)b
.-
isn’t covered byw
and thus your existing patterns would not matchbg-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 add0
to the end of the capture group before the word boundary (b
) for the stipulation that it should match an ending0
.b(bg-[w-]*0)b
on regex101b(text-[w-]*0)b
on regex101you can try this:
This pattern should accurately match your requirement:
b
word boundary (start of word)bg-
literal match for charactersb
,g
, and-
(hyphen)( )+
one or more:w+
one or more word-characters[0-9A-Za-z]+
-
hyphen (literal match)d
one digit[0-9]
0{2}
number zero0
(literal match){2}
two times00
b
word boundary (end of word)g
flag – global search (find all matches)Pattern Diagram: