what is the difference between the two regex(negative lookaround)?

benson

i could match content between tr tags with this regex:

<tr\s+class='test'>((?!</tr>).)*</tr>

but if i put the star quantifiers inside the parenthesis right next to the dot metacharacters,they match only the whole pattern with capturing group empty.

$string = "<tr class='test'>
<td>test1</td>
</tr>
 <div class='ignored' >text text</div>
 <tr class='test'>
 <td>test2</td>
 </tr>";


preg_match_all("|<tr\s+class='test'>((?!</tr>).*)</tr>|si",$string,$matches);

print_r($matches);

i know what lookaround is but i'm not quite sure what exactly cause the difference. hope someone can shed some light on this. Thank you!

Jerry
((?!</tr>).)*

The repetition is applied to ((?!</tr>).) and there is a single . and a single lookahead. Therefore, this will check each and every . (at each repetition) and make sure they are not followed by </tr>.

((?!</tr>).*)

This is actually (?!</tr>).* in disguise. There is a single lookahead and a single .*. The lookahead will check only the first ., but not the others, which is why everything will be matched, unless the immediate dots after the lookahead matches </tr>.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

what is the difference between the two regex(negative lookaround)?

From Dev

What is difference between these two statements?

From Dev

What is the difference between this two condition?

From Dev

What is the difference between these two instances?

From Dev

What is the difference between these two params?

From Dev

what is the difference between these two methods?

From Dev

What is the difference between these two SQL?

From Dev

What is the difference between these two examples?

From Dev

What is the difference between these two syntax?

From Dev

What is the difference between these two declarations

From Dev

what is the difference between these two lines

From Dev

what is the difference between these two programmes

From Dev

What is the difference between these two assignments?

From Dev

What is the difference between these two commands?

From Dev

What is difference between these two Codes

From Dev

What is difference between two series?

From Dev

What is Difference between the following two?

From Dev

R: regular expression lookaround(s) to grab whats between two patterns

From Dev

What is the reason for the difference between these two urlencodings of url

From Java

what the difference between the two codes (Spring Boot)?

From Dev

What is the difference between these two mongo "queries"?

From Dev

What is the difference/advantages between these two declaration styles

From Dev

What is the difference between these two functions in Javascript?

From Dev

What is the difference between these two function signatures?

From Dev

What is the difference between these two selectors using “:not”?

From Dev

What's the difference between these two async methods?

From Dev

What is the difference between these two Pig data types?

From Dev

What's the difference between these two function expressions?

From Dev

What is the difference between these two cases of adding a string?

Related Related

  1. 1

    what is the difference between the two regex(negative lookaround)?

  2. 2

    What is difference between these two statements?

  3. 3

    What is the difference between this two condition?

  4. 4

    What is the difference between these two instances?

  5. 5

    What is the difference between these two params?

  6. 6

    what is the difference between these two methods?

  7. 7

    What is the difference between these two SQL?

  8. 8

    What is the difference between these two examples?

  9. 9

    What is the difference between these two syntax?

  10. 10

    What is the difference between these two declarations

  11. 11

    what is the difference between these two lines

  12. 12

    what is the difference between these two programmes

  13. 13

    What is the difference between these two assignments?

  14. 14

    What is the difference between these two commands?

  15. 15

    What is difference between these two Codes

  16. 16

    What is difference between two series?

  17. 17

    What is Difference between the following two?

  18. 18

    R: regular expression lookaround(s) to grab whats between two patterns

  19. 19

    What is the reason for the difference between these two urlencodings of url

  20. 20

    what the difference between the two codes (Spring Boot)?

  21. 21

    What is the difference between these two mongo "queries"?

  22. 22

    What is the difference/advantages between these two declaration styles

  23. 23

    What is the difference between these two functions in Javascript?

  24. 24

    What is the difference between these two function signatures?

  25. 25

    What is the difference between these two selectors using “:not”?

  26. 26

    What's the difference between these two async methods?

  27. 27

    What is the difference between these two Pig data types?

  28. 28

    What's the difference between these two function expressions?

  29. 29

    What is the difference between these two cases of adding a string?

HotTag

Archive