Hi all,
I am up to my neck in regular expressions, and I have this regular expression that works in javascript (and flash) that I just can't get working in PHP
Here it is:
var number
= '(?:-?\\b(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\\b)';
var oneChar = '(?:[^\\0-\\x08\\x0a-\\x1f\"\\\\]'
+ '|\\\\(?:[\"/\\\\...
This was a fascinating debugging experience.
Can you spot the difference between the following two lines?
StringReplace["–", RegularExpression@"[\\s\\S]" -> "abc"]
StringReplace["-", RegularExpression@"[\\s\\S]" -> "abc"]
They do very different things when you evaluate them. It turns out it's because the string being replaced in the ...
Okay, I've been working through a set of string replacments for bbcode style tags in my forum, replacing [b] and [i] etc is fairly simple as I can replace them directly without issue.
There are two tags that are giving me problems, as what I need to do with them is more complex. [quote] and [url] are fine, but, I would like to give use...
I have the following code:
preg_match_all('/(.*) \((\d+)\) - ([\d\.\d]+)[,?]/U',
"E-Book What I Didn't Learn At School... (2) - 3525.01, FREE Intro DVD/Vid (1) - 0.15",
$match);
var_dump($string, $match);
and get the following ouput:
array(4) {
[0]=>
array(1) {
[0]=>
string(54) "E-Book What I Didn't Learn At Schoo...
I have a text source with nulls in it and I need to pull them out along with my regex pattern. Can regex even match a null character?
I only realized I had them when my pattern refused to match and when I pasted it into Notepad++ it showed all the null characters.
...
Is it possible to construct a PCRE-style regular expression that will only match each letter in a list only once?
For example, if you have the letters "lrsa" and you try matching a word list against:
^[lrsa]*m[lrsa]*$
you're going to match "lams" (valid), but also "lamas" (invalid for our purposes because you only had one "a"). If yo...
I found a function online for turning a url within a string into a clickable link. However, when the url contains a hashtag it doesn't work. eg. http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759
Here's the part of the function concerned:
$ret = preg_replace(
"#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#",
"\\1<a ...
I have a PHP regular expression that has been functioning fairly well to parse some odd legacy client templates until recently when we found an escaped question mark (\?) included in a template expression. I'm not strong enough with my regular expression-fu to wrap my feeble noodle around a negative look ahead or some techno-mumbo-jumbo ...
There has always been a confusion with preg_match in php.
I have a string like this:
apsd_01_03s_somedescription
apsd_02_04_somedescription
Can I use preg_match to strip off anything from 3rd underscore including the 3rd underscore.
thanks.
...
The regular expression class (rxregexp.dll) that comes with ooRexx (I'm on 4.0.0) is relatively low on function compared, say, with Python's re module (even at 2.5.2).
It appears to have no assertions, no facilities for group extraction, or for substitution. Greedy or lazy matching is a global pattern option, rather than flagged by an a...
Hi guys, i have this C++ program (actually it's just a snippet) :
#include <iostream>
#include <pcre.h>
#include <string>
using namespace std;
int main(){
string pattern = "<a\\s+href\\s*=\\s*\"([^\"]+)\"",
html = "<html>\n"
"<body>\n"
"<a href=\"example_link_1\"/>\n"
...
Hi all,
I am wondering if someone could please help me convert a piece of PHP code that is now deprecated.
Here is the single line I am trying to convert:
if(eregi(trim ($request_url_handler[$x]),$this->sys_request_url) && $this->id_found == 0){
It is part of a function that return the configuration settings for a website. Below is ...
I have one string like the following (the number of the {} is unknown):
{test}{test1}{test2}{test3}{test4}
Now I like to get the content in {} out and put them into array. How can I do this? I tried:
preg_match( "/(\{{\S}+\}*/)*")
But the result is wrong. Thanks so much for anyone's help.
...
I have some code validating a string of 1 to 32 characters, which may contain only alpha-numerics and hyphens ('-') but may not begin or end with a hyphen.
I'm using PCRE regular expressions & PHP (albeit the PHP part is not really important in this case).
Right now the pseudo-code looks like this:
if (match("/^[\p{L}0-9][\p{L}0-9-]{...
Hi all,
I've got the following regular expression that works fine on my testing server, but just returns an empty string on my hosted server.
$text = preg_replace('~[^\\pL\d]+~u', $use, $text);
Now I'm pretty sure this comes down to the hosting server version of PCRE not being compiled with Unicode property support enabled. The diffe...
Hi,
i tried redirecting some folders to the subdomains with the same names as the folders. I tried this way but it didn't work:
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(test1|test2)(.*?)$ http://$1.domain.com$2 [R=301,L]
I guess the problem is that the alternation of folders doesn't return a result that i can get ...
How do I add the character - within the preg_match?
preg_match('#^(\w+/){0,2}\w+\.\w+$#', $string)
But it must be before the last . within the string. I've tried just about everything I know here. I know that the - needs to be escaped. So I tried to escape it in various places, but it's not working :(
argggg
...
a ip or other string, like "11.22.33.44" or "aa.bb.cc.dd". basically, I think it is very easy, (([\d\w]+)+\.)+[\d\w]+
but the problem is which group these submatches are in. not like ip, some string is consist of lots of words+separate
in pcre, I don't know how to extract it all words -- "aa bb cc dd ..."
...
I have a PCRE regex that looks like this
s/(<input.+?)alt(=".+?".*?>)/$1title$2/
Can anybody help me with making that work on sed?
Eventually can anybody point me to some guide/blog post/whatever that explains differences between sed regex and PCRE?
...
The input: we get some plain text as input string and we have to highlighight all URLs there with <a href={url}>{url></a>.
For some time I've used regex taken from http://flanders.co.nz/2009/11/08/a-good-url-regular-expression-repost/, which I modified several times, but it's built for another issue - to check whether the whole input st...