Say $d is a directory path and I want to ensure that it starts and ends with exactly one slash (/). It may initially have zero, one or more leading and/or trailing slashes.
I tried:
preg_replace('%^/*|/*$', '/', $d);
which works for the leading slash but to my surprise yields two trailing slashes if $d has at least one trailing slash...
Hi,
i need a regex for: 123,456,789,123,4444,... basically comma separated values. The INT part can be 1-4 numbers long, followed by a comma...always in this form...
/^([0-9]{1,4})(\,)?$/
This obviously doesn't work...
Thanks!
...
On a site I am working on I have a requirement that usernames not start with <alpha><alpha>_
So these should not be allowed:
SU_Coolguy
MR_Nobody
my_Pony
But these should be ok:
__SU_Coolguy
MRS_Nobody
YourPony
In the framework I am using, I am only able to validate against matching regular expression, not non-matchi...
for example:
(test)rrr(/test) -> (ll)rrr(/ll)
regexp: ( (test)(.*?)(test) )
...
Hi,
I'm trying to devise a regex pattern (in PHP) which will allow for any alternation of two subpatterns. So if pattern A matches a group of three letters, and B matches a group of 2 numerals, all of these would be OK:
aaa
aaa66bbb
66
67abc
12abc34def56ghi78jkl
I don't mind which subpattern starts or ends the sequence, just that af...
I have this line in one of my scripts and its throwing a deprecated error.
eregi_replace( '\.([a-z]{3,4})$', "-{$width}x{$height}.\\1", $src );
Can someone show me how to turn this into preg_replace and tell me why and which bits of it need to change so I can learn for future changes? I have had a go myself but where this bit of code...
Hi, Im quite new to stackoverflow so I dont know if this question has been asked before, but I cant seem to find any past questions which hint at the answer. Any help is really appreciated and thanks in advance.
I have this text:
{
1282837200, -- [1]
"Type", -- [2]
"Name", -- [3]
"Reason", -- [4]
Amount, -- [5]
}, -- [...
I'm trying to find an optimized regex to return the N words (if available) around another one to build a summary. The string is in UTF-8, so the definition of "words" is larger than just [a-z]. The string that serves as the reference word could be in the middle of a word or not directly surrounded by spaces.
I've already got the followi...
I am trying to replace in a string all non word characters with empty string expect for spaces and the put together all multiple spaces as one single space.
Following code does this.
$cleanedString = preg_replace('/[^\w]/', ' ', $name);
$cleanedString = preg_replace('/\s+/', ' ', $cleanedString);
But when I am trying to use mb_ereg...
I'm trying to match a string that looks something like this:
<$Fexample text in here>>
with this expression:
<\$F(.+?)>{2}
However, there are some cases where my backreferenced content includes a ">", thus something like this:
<$Fexample text in here <em>>>
only matches example text in here <em in the backreference. What do I ne...
Hi, I am trying to extract 1 and 125 from this text with PHP:
preg_match("/^(?P<digit>\d+)/", "1 Foo ($125)",$m)
Can you please help?
Thanks
...
Hi,
Given the following regular expressions:
- alice@[a-z]+\.[a-z]+
- [a-z]+@[a-z]+\.[a-z]+
- .*
The string [email protected] will obviously match all three regular expressions. In the application I am developing, we are only interested in the 'most specific' match. In this case this is obviously the first one.
Unfortunately th...
Hi,
Is there a way of determining if the regular expression only matches fixed-length strings ?
My idea would be to scan for *,+ and ? Then, some intelligent logic would be required to to look for {m,n} where m!=n.
It is not necessary to take the | operator into account.
Small example: ^\d{4} is fixed-length; ^\d{4,5} or ^\d+ are variab...
After reading polygenelubricants's series of articles on advanced regular expressions techniques (particularly How does this Java regex detect palindromes?), I decided to attempt to create my own PCRE regex to parse a palindrome, using recursion (in PHP).
What I came up with was:
^(([a-z])(?1)\2|[a-z]?)$
My understanding of this expr...
This question is an educational demonstration of the usage of lookahead, nested reference, and conditionals in a PCRE pattern to match ALL palindromes, including the ones that can't be matched by the recursive pattern given in the PCRE man page.
Examine this PCRE pattern in PHP snippet:
$palindrome = '/(?x)
^
(?:
(.) (?=
...
I have upgrade the (pcre-devel-6.6-1.1, pcre-6.6-1.1) support on test linux machine having centos-5.0. I have restarted the apache, But in php information it is still showing the old version of PCRE (PCRE Library Version-5.0 13-Sep-2004), I want to upgrade this version
on machine please guide me to update this version.
Thanks in advanc...
When using preg_replace() in PHP with strings generated at runtime, one can protect special regex characters (such as '$' or '+') in the search string by using preg_quote(). But what's the correct way to handle this in the replacement string? Take this code for example:
<?php
$haystack = '...a bit of sample text...';
$replacement = '\\...
For example,the regex below will cause failure reporting lookbehind assertion is not fixed length:
#(?<!(?:(?:src)|(?:href))=["\']?)((?:https?|ftp)://[^\s\'"<>()]+)#S
Such kind of restriction doesn't exist for lookahead.
...
I'm trying to write a regular expression for matching the following HTML.
<span class="hidden_text">Some text here.</span>
I'm struggling to write out the condition to match it and have tried the following, but in some cases it selects everything after the span as well.
$condition = "/<span class=\"hidden_text\">(.*)<\/span>/";
If ...
This is a newbie question but I hope I can express my question as clearly as possible.
I'm trying to do pattern matching in C++.
I've downloaded the Win32 version of PCRE from here and I've placed the downloaded pcre3.dll and pcreposix3.dll files into the folder of Dev-CPP's lib folder (I'm using Bloodshed Dev-C++ 4.9.9 IDE).
I've a...