Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. PHP perl regular expression - URL not preceded by equal sign and possible single or double quote

PHP perl regular expression - URL not preceded by equal sign and possible single or double quote

Scheduled Pinned Locked Moved Regular Expressions
regextutorialquestionphpperl
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doug Davis 2024
    wrote on last edited by
    #1

    I'm trying to create a perl regular expression that matches a URL that is not preceded by an equal sign and one single or double quote (optional) ignoring whitespace. The code below gives an error:

    Warning: preg_replace(): Compilation failed: lookbehind assertion is not fixed length at offset 0

    I know my URL regular expression isn't perfect, but I'm more focused on how to do the negative lookbehind or how to express this in some other way. For example, in the code below, I would like for the expression to match http://www.url1.com/ and http://www.url3.com/, but not the other URLs. How can I do this? The code below gives a warning and does not populate the $matches variable. The Code:

    $html = "
    http://www.url1.com/
    = ' http://www.url2.com/
    'http://www.url3.com/
    [Testing1](http://www.url4.com/)
    ![](https://url5.com)Testing2";
    
    $url\_pregex = '((http(s)?://)\[-a-zA-Z()0-9@:%\_+.~#?&;//=\]+)';
    $pregex = '(?
    

    Perl Regex in PHP, using ` instead of /:

    '`(?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups