2

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

1
  • Can you give an example of your input data, and then an example of what you would want out of that data? Commented Mar 13, 2012 at 10:15

1 Answer 1

3

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].

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.