pcre

Recursive regex in PHP

Possible Duplicate: RegEx match open tags except XHTML self-contained tags Hi to all! Could you please explain to me a little about a recursive regular expression in PHP PCRE? So, for example I have general nested html: <div id="first"> <b>some text</b> <div id="second"> <div id="third"> ... </...

PHP PCRE replace markup style

Hi, I need a PCRE expresssion (regex) to match and replace a certain attribute and value related to a markup element, something like this : <div style="width:200px;"></div> into <div style="width:100px;"></div> What I have now, parsed by simplehtmldom is the style content in plain text, like this : width:200px; How can I match ...

PCRE to find all possible matching values

I am using PCRE in PHP, and I need to find a way to generate say an array of all possible matching values. Any ideas? For example if I had R[2-9]{1} I would want: R2 R3 R4 R5 R6 R7 R8 R9 Thanks for the help, -Eric ...

Preg_match help for finding count

HI all i have a string <font size="+1"><b>Open Directory Sites</b></font> (1-20 of 10000)<p> i need to get 10000 as answer .. how i use preg_match ??? Note: this is implortant that the multiple occurance of match Thanks in advance ...

Regular expression for matching a variety of types of numbered lists

I'd like to create a (PCRE) regular expression to match all commonly used numbered lists, and I'd like to share my thoughts and gather input on way to do this. I've defined 'lists' as the set of canonical Anglo-Saxon conventions, i.e. Numbers 1 2 3 1. 2. 3. 1) 2) 3) (1) (2) (3) 1.1 1.2 1.2.1 1.1. 1.2. 1.3. 1.1) 1.2) 1.3) (1.1) (1.2) (...

PHP: Trouble with preg_match_all() return

I'm writing this quick script to extract chatroom names from the source of a webpage. I'm grabbing the data with fopen() and fgets() and that all returns fine. My regex is /#[a-zA-z]+/, which does seem to work. However I can not get preg_match_all() to return a concise list of data. preg_match_all("/#[a-zA-z]+/", $contents, $foo, PREG_...

Trying to use preg_match on extracted html page but this is perplexing me

I've been trying the below script (within a larger app I'm working on) for hours now and I just can't understand what the problem is, no matter what I get "Notice: Undefined offset: 1" meaning that its having some problem putting the result into an array from the preg_match... I did a process that was nearly identical to a similar page e...

PHP Preg (regex) extracting last value from a string? not as simple as I thought

I'm trying to use PHP preg to extract the integer at the end of the string below, in the example its "4", but could be any number coming after "INBOX/", also the "[email protected]" is a variable so it could be any address STRING I'M EXTRACTING FROM: /m/[email protected]/folder/INBOX/4 /STRING I've been going in c...

Looking for Win32 precompiled PCRECPP

I am having trouble finding a precompiled Win32 distribution of PCRE that also includes PCRECPP. The two archives I could find only include "pcre.h". http://gnuwin32.sourceforge.net/packages/pcre.htm http://www.psyon.org/projects/pcre-win32/ ...

Regex fails to match for no obvious reason.

Consider the two following regular expression snippets and dummy HTML that it should be matching: Apparently, I can only post one link until I get more reputation, so the link below contains the three links I referenced above: http://pastebin.com/Qj1uxfdk The difference between the two snippets, if anyone is wondering, is a removed ((...

string manipulation pre_replace or str_replace

I need to replace a word with another word. But $var= str_replace($linklabel[$k], $linklabelmod[$k], $var); is not giving the desired result. For example i have a string $var="the theory of them thesis"; $linklabel[1]="the"; $linklabelmod[1]="hhh"; What i need is, i just want to replace the word "the". But since "the" is repeat...

PHP expressions fail when changing from ereg to preg_match

I have a class that uses PHP's ereg() which is deprecated. Looking on PHP.net I thought I could just get away and change to preg_match() But I get errors with the regular expressions or they fail!! Here are two examples: function input_login() { if (ereg("[^-_@\.A-Za-z0-9]", $input_value)) { // WORKS // if (preg_match("[^-_@\....

Problem with ereg deprecated

Can some please help me to rewrite these code: if (eregi($asked,$accepted)) { $this->plot_type = $which_pt; return true; } else { $this->DrawError('$which_pt not an acceptable plot type'); return false; } Any help will be highly appreciated, I have tried all the fix I got through Google but none has been able to fix it. Thanks. ...

how to force preg_match preg_match_all to return only named parts of regex expression

example: <?php $string = "This is some text written on 2010-07-18."; preg_match('|(?<date>\d\d\d\d-\d\d-\d\d)|i',$string,$arr_result); print_r($arr_result); ?> returns: Array ( [0] => 2010-07-18 [date] => 2010-07-18 [1] => 2010-07-18 ) but I want it to be: Array ( [date] => 2010-07-18 ) in php's pdo object there ...

How can i count the number of words between two words?

Hi! How can i count the number of words between two words? $txt = "tükörfúrógép banana orange lime, tükörfúrógép cherry árvíztűrő orange lyon cat lime mac tükörfúrógép cat orange lime cat árvíztűrő tükörfúrógép banana orange lime orange lime cat árvíztűrő"; The two words: 'árvíztűrő' and 'tükörfúrógép' I need this retur...

String search in a packet

Assume we capture packets with the C API of libpcap. Is it efficient to parse some payload strings with string search strstr() in line speed (e.g. Mbps/Gbps)? For example strstr(payload,"User-Agent"); Would it be more efficient to do it with a regular expression pattern matching library, such as libpcre? If we want to do that only for ...

Converting PCRE recursive regex pattern to .NET balancing groups definition

PCRE has a feature called recursive pattern, which can be used to match nested subgroups. For example, consider the "grammar" Q -> \w | '[' A ';' Q* ','? Q* ']' | '<' A '>' A -> (Q | ',')* // to match ^A$. It can be done in PCRE with the pattern ^((?:,|(\w|\[(?1);(?2)*,?(?2)*\]|<(?1)>))*)$ (Example test case: http://www.ideone.com/...

Perl regexp /(\r\n|\r|\n)/

Hi, I want to know how this ambiguous pattern is solved in perl(more generally everything that use libpcre): /(\r\n|\r|\n)/ When the pattern sees \r\n will it match one time or twice? And what is the rules face to this situation? Thanks ...

Whats wrong with this regular expression?

I have the following regular expression to find word in text and highlight them Using the word surface for testing purposes. /((?<=[\W])surface?(?![\w]))|((?<![\w])surface?(?=[\W]))/iu It matches all occurences in the following text. surface-CoP-20-70-0000-04-02_Pre-Run_Tool_Verification_Programming_and_surface_Tare surface_revC.pdf...

regex int or float

Hi, My regex won't work on single digit number /^[0-9]{1,7}\.?[0-9]{1,2}$/ I need it to work on unsigned numbers: 1 (single digit numbers, without fractions) - currently it fails on them 1.0; 0.31 (floating point numbers) Number before fraction can be 1-7 digits; after fraction 1-2 digits. Thanks you! ...