Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7834097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:03:39+00:00 2026-06-02T13:03:39+00:00

I’m not a regex expert, but after a couple hours I’ve built this regex:

  • 0

I’m not a regex expert, but after a couple hours I’ve built this regex:

#\[url=(?!.*?<div onclick="unveil_spoiler.*?\[/url\])([^_\W]+?://.*?)\](.+?)\[/url\]#i

Which is a case-insensitive:

\[url=(?!.*?<div onclick="unveil_spoiler.*?\[/url\])([^_\W]+?://.*?)\](.+?)\[/url\]

To match [url=xxxx://yyyy]zzzz[/url] patterns, except if it contains a <div onclick="unveil_spoiler string between [url= and and [/url].

Now I’m trying to add a similar check, to don’t return a match if it contains a \[url.*?\] between the \[url= and \[/url\]. I’ve tried many ways but I can seem to find a 100% working one.

First I tried adding another negative lookahead very similar to the one already present in my regex, which works partially, but then it seems like the lookahead goes through until the end of the line – until the last \[/url\] – for each match, I wanted the lookahead to stop at the first \[/url\] as the capturing group does.

Here’s a string for debugging:

[url=http://www.match.com]Match[/url][url=http://www.nomatch.com<div onclick="unveil_spoiler"]No match[/url][url=http://www.match.com]Match[/url][url=http://www.nomatch.com]<div onclick="unveil_spoiler" No match[/url]
[url=http://www.nomatch.com]No <div onclick="unveil_spoiler"match[/url][url=http://www.match.com]Match[/url][url=http://www.nomatch.com]No <div onclick="unveil_spoiler" match[/url][url=http://www.match.com]Match[/url]

[url=http://www.match.com]Match[/url][url=http://www.match.com][b]Match[/b][/url][url=http://www.match.com]Match[/url][url=http://www.match.com]Match[/url]

[url=http://www.thisshouldntmatch.com[url=http://www.match.com]Match[/url]This shouldn't match[/url]

[url=http://www.thisshouldntmatch.com[url=http://www.thisshouldntmatch.com[url=http://www.match.com]Match[/url]]This shouldn't match[/url]This shouldn't match[/url]

[url=http://www.thisshouldntmatch.com[url=http://www.match.com]Match[/url]This shouldn't match[/url][url=http://www.match.com]Match[/url]

[url=http://www.thisshouldntmatch.com]This shouldn't match[url=http://www.match.com]Match[/url][url=http://www.match.com]Match[/url][/url]

[url=http://www.match.com]Match[/url][url=http://www.match.com]Match[/url][url=http://www.match.com]Match[/url][url=http://www.match.com]Match[/url]

With the regex posted in the beginning of the post, it’ll match the 2 matches in the first line perfectly. Now I wanted it to don’t return a match when there’s a \[url.*?\] inside of the match, I’ve tried this regex:

\[url=(?!.*?\[url.*?\].*?\[/url.*?\])(?!.*?<div onclick="unveil_spoiler.*?\[/url\])([^_\W]+?://.*?)\](.+?)\[/url\]

And this:

\[url=(?!.*?(?:<div onclick="unveil_spoiler|\[url.*?\]).*?\[/url\])([^_\W]+?://.*?)\](.+?)\[/url\]

Which won’t return matches when there’s a \[url.*?\] inside of the match, but then it also stops matching the first match of the first line (in the example string) which it should (and as the first regex does). That is, it’ll only match the last valid match of each line then.

I think it’s a problem with the lookahead which doesn’t stop at the first \[/url\], is there any way to make it lazy/fix it then?

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:03:39+00:00Added an answer on June 2, 2026 at 1:03 pm

    Does this work?

    \[url=[^\[<]*?\](?:(?!(\[url)|<).)*?\[\/url\]

    http://regexr.com?30mna

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.