I have this:
[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)
It matches for:
www.example.com
http://example.com.nz
example.com
http://www.example.com?2rjl6
example.com/first/second
https://example.us.edi?34535/534534?dfg=g&fg
etc...
I want no match if any of the above URLs are enclosed in square brackets [ ] like this:
[www.example.com]
[http://example.com.nz]
etc...
The text is long and may or may not contain more than one URL, spaces, line breaks, and so on.
e.g.
Lorem ipsum dolor sit amet, consectetur [http://example.com.nz] llamcorper et lacus. Morbi sodales convallis lectus a efficitur: example.com/first/second vitae nisl placerat.
Fusce non ipsum a augue http://example.com.nz http://www.example.com?2rjl6 aculis augue. Nullam eu nulla lectus.
In this case there should be only 3 matches.
I tried adding:
(?![^\[]*\])
But it doesn't work as expected.
Can you help me with this or recommend another approach? Thanks.