tt0686
tt0686

Reputation: 1849

Regular Expression alternation not working

Good afternoon

I am testing my Regular Expression on regex101.com site. Regular Expression:

<button[^<]*>.*[\s\S]*<\/button>|
<iframe[^<>]*\/>|
<tr>[^<td>]*<\/tr>

Test Text

<table width="30px">
<P>Teste</p><iframe src="teste" /><p>Test</p>
<div><span>Teste Regex</span></div>
<p>Test</p><button onclick="myFunction()">Click me</button>
<table>
<tr><td>34</td></tr>>
</table>

Why only the <button[^<]*>.*[\s\S]*<\/button> code is matched ? If i clear this part of the regular expression and stay only with this:

<iframe[^<>]*\/>|
<tr>[^<td>]*<\/tr>

Only the <iframe.. is matched

Why is this happen and how can I fix it ?

Upvotes: 0

Views: 148

Answers (1)

Federico Piazza
Federico Piazza

Reputation: 31045

You have to remove the new lines before your OR and also set the G (global flag).

Working demo

enter image description here

Upvotes: 1

Related Questions