skip to Main Content

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

https://regexr.com/7p8fd

🧐

3

Answers


  1. 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.

    Login or Signup to reply.
  2. you can try this:

    /(bg)+(-[a-zA-Z0-9]*)+0/g
    
    Login or Signup to reply.
  3. This pattern should accurately match your requirement:

    /bbg-(w+-)+d0{2}b/g
    
    • b word boundary (start of word)
    • bg- literal match for characters b, g, and - (hyphen)
    • ( )+ one or more:
      • w+ one or more word-characters
        • same as [0-9A-Za-z]+
      • - hyphen (literal match)
    • d one digit
      • same as [0-9]
    • 0{2} number zero 0 (literal match)
      • {2} two times
      • same as 00
    • b word boundary (end of word)
    • g flag – global search (find all matches)

    Pattern Diagram:

    regex pattern diagram

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search