Click here to Skip to main content
15,886,919 members
Home / Discussions / Regular Expressions
   

Regular Expressions

 
QuestionREGEX to find space followed by number 1 then letter Pin
Richard Parker from London24-Apr-24 2:16
Richard Parker from London24-Apr-24 2:16 
QuestionPHP perl regular expression - URL not preceded by equal sign and possible single or double quote Pin
Doug Davis 202427-Mar-24 9:37
Doug Davis 202427-Mar-24 9:37 
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/
<a href='http://www.url4.com/'>Testing1</a>
<img src='https://url5.com'>Testing2</a>";

$url_pregex = '((http(s)?://)[-a-zA-Z()0-9@:%_+.~#?&//=]+)';
$pregex = '(?<!\\s*=\\s*[\'"]?\\s*)'.$url_pregex;
$output = preg_match('`'.$pregex.'`i', $html, $matches);

preg_match('`'.$pregex.'`i', $html, $matches);

var_export($matches);



Perl Regex in PHP, using ` instead of /:

PHP
'`(?<!\\s*=\\s*[\'"]?\\s*)((http(s)?://)[-a-zA-Z()0-9@:%_+.~#?&//=]+)`i'


modified 27-Mar-24 16:37pm.

QuestionModify Regex To Disallow Spaces Pin
mcfc4heatons26-Mar-24 11:03
mcfc4heatons26-Mar-24 11:03 
SuggestionRe: Modify Regex To Disallow Spaces Pin
Richard Deeming26-Mar-24 22:47
mveRichard Deeming26-Mar-24 22:47 
QuestionMatching Floating Point Numbers Range with a Regular Expression Pin
Dagobert19-Feb-24 2:10
Dagobert19-Feb-24 2:10 
AnswerRe: Matching Floating Point Numbers Range with a Regular Expression Pin
Richard Deeming9-Feb-24 2:19
mveRichard Deeming9-Feb-24 2:19 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
trønderen9-Feb-24 6:25
trønderen9-Feb-24 6:25 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
Dagobert19-Feb-24 6:49
Dagobert19-Feb-24 6:49 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
jschell9-Feb-24 12:34
jschell9-Feb-24 12:34 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
Dagobert19-Feb-24 10:22
Dagobert19-Feb-24 10:22 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
jschell9-Feb-24 12:37
jschell9-Feb-24 12:37 
GeneralRe: Matching Floating Point Numbers Range with a Regular Expression Pin
Richard Deeming11-Feb-24 21:47
mveRichard Deeming11-Feb-24 21:47 
AnswerRe: Matching Floating Point Numbers Range with a Regular Expression Pin
Pete O'Hanlon12-Feb-24 0:04
mvePete O'Hanlon12-Feb-24 0:04 
QuestionRegular expression for City name Pin
KiranKumar V 20247-Feb-24 19:08
KiranKumar V 20247-Feb-24 19:08 
AnswerRe: Regular expression for City name Pin
Dave Kreskowiak7-Feb-24 19:19
mveDave Kreskowiak7-Feb-24 19:19 
GeneralRe: Regular expression for City name Pin
KiranKumar V 20247-Feb-24 19:27
KiranKumar V 20247-Feb-24 19:27 
GeneralRe: Regular expression for City name Pin
Dave Kreskowiak8-Feb-24 3:18
mveDave Kreskowiak8-Feb-24 3:18 
GeneralRe: Regular expression for City name Pin
KiranKumar V 20248-Feb-24 3:26
KiranKumar V 20248-Feb-24 3:26 
GeneralRe: Regular expression for City name Pin
Richard Deeming8-Feb-24 3:38
mveRichard Deeming8-Feb-24 3:38 
GeneralRe: Regular expression for City name Pin
Dave Kreskowiak8-Feb-24 3:56
mveDave Kreskowiak8-Feb-24 3:56 
GeneralRe: Regular expression for City name Pin
Richard MacCutchan8-Feb-24 4:36
mveRichard MacCutchan8-Feb-24 4:36 
JokeRe: Regular expression for City name Pin
jschell8-Feb-24 4:44
jschell8-Feb-24 4:44 
GeneralRe: Regular expression for City name Pin
Dave Kreskowiak8-Feb-24 3:55
mveDave Kreskowiak8-Feb-24 3:55 
AnswerRe: Regular expression for City name Pin
k50547-Feb-24 20:02
mvek50547-Feb-24 20:02 
AnswerRe: Regular expression for City name Pin
Pete O'Hanlon8-Feb-24 4:10
mvePete O'Hanlon8-Feb-24 4:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.