Vit Kos
Vit Kos

Reputation: 5755

Extracting links using regex via php

need a little help with the regexp i make... have some text where links are encoded like

[NameLink ->link] or [NameLink->link]

The link can be without http:// or www. Tried to get it using this pattern

/\[.{1,}\-\>.{1,}\]/

but if there are 2 such encoded links in a row then it doesn't separate them and takes also the content between two links. Can someone tell me what's the problem? Thank you

Upvotes: 2

Views: 77

Answers (1)

Jonas Schäfer
Jonas Schäfer

Reputation: 20718

Use +? instead of {1,}. Also, have a read on greedy vs. nongreedy.

You may want to strip spaces using \s* around your .+?, this allows for both [NameLink -> link] and [NameLink ->link].

Upvotes: 3

Related Questions