Simon
Simon

Reputation: 2643

Php Regex exclude a certain pattern already matched

Hi there I need a hand with the pattern below:

(?<=\")([0-9\.\/])+(?=\")

Content

<ul>
<li><a href="../">..</a></li>
<li><a href="1.0/">1.0/</a></li>
<li><a href="1.1/">1.1/</a></li>
<li><a href="1.23/">1.23/</a></li>
</ul>

The above pattern selects ../, 1.0/, 1.1/, 1.23/

I don't want to match ../ but any permutation of number,period and / should match.

Give me a hand please.

Thanks as always.

Upvotes: 4

Views: 1538

Answers (2)

Joko Wandiro
Joko Wandiro

Reputation: 1987

I modify your regex with adding negative lookahead ( (?!\.) ).

(?<=\")(?!\.)([0-9\.\/])+(?=\")

Upvotes: 1

codaddict
codaddict

Reputation: 455400

You can put a negative lookahead assertion in your existing regex:

(?<=\")(?!\.\.)([0-9\.\/])+(?=\")
       ^^^^^^^^

See it

Upvotes: 3

Related Questions