I need help, below is a small VERY basic regex to somewhat validate an email, I do realize it does not work the greatest but for my needs it is ok for now.
It currently uses PHP's eregi function which php.net says is now a depreciated function and I should use preg_match instead, simply replacing erei with preg_match does not work, can...
Hi,
I'm trying to fetch data from a div (based on his id), using PHP's PCRE. The goal is to fetch div's contents based on his id, and using recursivity / depth to get everything inside it. The main problem here is to get other divs inside the "main div", because regex would stop once it gets the next </div> it finds after the initial <d...
Hello,
Here's a short regex example:
preg_match_all('~(\s+|/)(\d{2})?\s*–\s*(\d{2})?$~u', 'i love regex 00– / 03–08', $matches);
print_r($matches);
The regex only matches '03–08', but my intention was matching '00–' as well. What is the problem? Anyone could explain?
...
Hi,
I have some trouble matching the contents inside php tags.
Currently I have this code, but it's not working for me:
<?php preg_match_all('/<\?php(.+)\?>/', $str, $inside_php); ?>
I need to retrieve the contents so I can do other things with them, like eval().
...
i want to find first select ... from and replace that only, following code replace all select..from in sql query, i just need for first select..from
preg_replace('#select(.*?)from#is', "select count($expr) as counted from", $sql);
...
Hi, I am inexperienced with using C, and I need to use PCRE to get matches.
Here is a sample of my source code:
int test2()
{
const char *error;
int erroffset;
pcre *re;
int rc;
int i;
int ovector[OVECCOUNT];
char *regex = "From:([^@]+)@([^\r]+)";
...
Here's a small example (download, rename to .php and execute it in your shell):
test.txt
Why does preg_replace return NULL instead of the original string?
\x{2192} is the same as HTML "→" ("→").
...
So ereg won't be present in PHP6. And I don't really care, because I'm using PCRE functions. But for multibyte strings, I'm using mb_ereg_* functions. The question is: they'll be present in PHP6 in the mbstring extension, or I will have to switch to some kind of multibyte PCRE functions?
...
I am interested in the power of PCRE (Perl Compatible Regular Expressions) and wonder whether they are likely to become a de facto approach in all major languages (I am interested in Java). I am prepared to use a library if necessary.
I also could not find a good page in SO describing the pros and cons of PCRE so if this does not exist ...
I have a structured file with hierarchical text which describes a GUI in Delphi (a DFM-File).
Let's assume I have this file and I have to match all "Color = xxx" Lines, which are in the context of TmyButton (marked), but not those in other context. Within the TMyButton-Context there won't be a deeper hierarchical level.
object frmMain:...
I need to let the user specify a custom format for a function which uses vsprintf, and since PHP doesn't have glibc' register_printf_function(), I'll have to do it with PCRE.
My question is, what would be the best REGEXP to match % followed by any character and not having % before it, in an usable manner for programmatic use afterwards?...
Hi,
I'm trying to remove some deprecated code from a site.
Can anyone tell me the preg equivalent of
ereg_replace("<b>","<strong>",$content);
Thanks.
...
Normally I would just do this.
$str = preg_replace('#(\d+)#', ' $1 ', $str);
If I knew it was going to be utf-8 I would add a lowercase "u" modifier to the pattern and I think I would be good. But because of reports of utf-8 taking 2x and in some cases 3x the storage space than it would take if the native character set were used, I'm ...
If I have a string $random, and I want to throw out everything except commas and numbers, how could I do this in PHP PCRE?
I know \d will match numbers, but I don't get the rest of PCRE.
...
I'm having a problem with PHP PCRE, and I'm used to POSIX, so I'm not too sure about what I'm doing wrong. Basically, this function is matching up to 10 numbers separated by commas. However, it's also matching the string sdf (and probably many others), which I don't see the reason for. Can anyone help me?
$pattern='^\d{0,5},? ?\d{0,5},?...
How do I ignore case when using pcre_compile and pcre_exec?
pcre_exec(
pcre_compile(pattern,0,&error,&erroroffset,0),
0, string, strlen(string), 0, 0, ovector, sizeof(ovector));
what option do i use and where do i specify it?
...
first, this is using preg.
String I'm trying to match:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b c d xp
My regex and their matches:
(\S*\s*){0,1}\S*p = "d xp"
(\S*\s*){0,2}\S*p = "c d xp"
(\S*\s*){0,3}\S*p = NO MATCH (expecting "b c d xp"
(\S*\s*){0,4}\S*p = entire string
(\S*\s*){0,5}\S*p = entire string
Oddly, if I remove a single ...
Why does the following segfault, and how can I prevent it?
<?php
$str = ' <fieldset> <label for="go-to">Go to: </label> '
. str_repeat(' ', 10000)
. '<input type="submit" value="Go" /> </fieldset> </form>';
preg_match_all("@
</?(?![bisa]\b)(?!em\b)[^>]*> # starting tag, must not be one of several inline tags
(?:[^<]|<...
I'm trying to search a UTF8-encoded string using preg_match.
preg_match('/H/u', "\xC2\xA1Hola!", $a_matches, PREG_OFFSET_CAPTURE);
echo $a_matches[0][1];
This should print 1, since "H" is at index 1 in the string "¡Hola!". But it prints 2. So it seems like it's not treating the subject as a UTF8-encoded string, even though I'm passing...
EDIT: Optimization results at end of this question!
hi, i have a following code to first scan files in a specific folder and then read every file line by line and after numerous "if...else if" write new modified file to another folder with the name name as it was when opened.
The problem is that writing a file line by line seems to be ...