Tomas Simanaitis
Tomas Simanaitis

Reputation: 63

Regex: Select anything in between

I'm using my custom button component like this -> <h-button text primary outline>. I want to write a regex that would let me select every button that has one or many props. I can easily select everything in the button tag using -> <h-button(.*?)> regex, but I don't know how to select only a specific word or two.

Example:

Let's say I have 3 buttons

<h-button text primary outline>
<h-button primary text outline>
<h-button text success outline>

And I want to find every button that has text and primary in it.

Expected result:

Regex should find these two buttons

<h-button text primary outline>
<h-button primary text outline>

Upvotes: 1

Views: 46

Answers (1)

Chalda Pnuzig
Chalda Pnuzig

Reputation: 396

Try this:

/<h-button .*?(text .*primary|primary .*text).*?>/

https://regex101.com/r/3POnQX/1

Upvotes: 3

Related Questions