Re: [PHP] Re: Regular Expression Backreference in subpattern.
Shiplu wrote: Sorry The previous code was wrong, Its the correct version, $x = a b;c d;e f;; preg_match('/(?Pkeys\w) (?Pvalues\w)/',$x,$m); print_r($m); Now I am using backrefrence \1 in in ?P option like (?P\1\d+). and I got the error. thought I best update for courtesy sake; I spent a good chunk of time on this yesterday, read all the regex stuff I could find, and the closest I could get was to use recursive sub patterns, however there was no way to make a named subpattern name (keys) be a backreference / variable.. ie $1 \1 \\1 will never work. even using this method you're still going to have to combine the two arrays to get what you want ($m['keys'] with $m['values']) Regards do let me know if you manage! Nathan ps: there may be something in the ?name syntax; I don't think so though.. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regular Expression Backreference in subpattern.
Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? $string = 'tdcharge/tdtd100/td'; preg_match('|td(.*)/tdtd(\d+)/td|', $string , $out); print_r( $out ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regular Expression Backreference in subpattern.
What's the complete row? e.g., trtdcharge/tdtd100/td/tr Or, are there other td cells in the row? Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regular Expression Backreference in subpattern.
On 9/27/08, Nathan Rixham [EMAIL PROTECTED] wrote: Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? $string = 'tdcharge/tdtd100/td'; preg_match('|td(.*)/tdtd(\d+)/td|', $string , $out); print_r( $out ); You didnt get my point,. your codes output will be Array (2) { [0] = charge, [1]= 100 } But I want this, Array (1) { charge = 100 } Thats why I used ?Pname syntax, In name I used \1, means the last matched patter would be the key. I can do this by preg_match_all(), then array_combine() funciton. But I was thinking if I could make it with calling only preg_match_all -- Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regular Expression Backreference in subpattern.
On 9/27/08, Al [EMAIL PROTECTED] wrote: What's the complete row? e.g., trtdcharge/tdtd100/td/tr Or, are there other td cells in the row? No TD cells. forget the real world problem. I made the exact replica of that. I need the sample work. -- Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regular Expression Backreference in subpattern.
Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? $pattern=%td(\w*)/tdtd(\d+)/td%; $str=tdcharge/tdtd100/td; preg_match($pattern, $str, $matches); Make a new array with $new= array($matches[1] = $matches[2]); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Regular Expression Backreference in subpattern.
Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? it seem's everybody is giving you the same answers; here's a definitive look at the problem (as far as I'm aware) all preg_* functions can only return back string's, or array's of strings; there is no method of returning back an associative array as you would like; the closest you can get is by using preg_replace or preg_replace_callback as follows: print_r( preg_replace_callback('|td(.*)/tdtd(\d+)/td|', create_function( '$matches', 'return array($matches[0],$matches[1]);' ), $string) ); this will fall as the internals of preg* casts the array to a string alternative: print_r( preg_replace('|td(.*)/tdtd(\d+)/td|e', 'array($1,$2)', $string) ); this will also fail as the internals of preg* casts the array to a string. similarly all other options you could go down such as simple explodes, strip_tags or even more complex stream filters will only allow you to return strings, or numerical array's of strings. This leaves you high and dry I'm afraid - the only thing for it is to create a simple function to handle this for you; something like function td_thing( $string ) { $a = preg_replace('|td(.*)/tdtd(\d+)/td|e', '$1 $2', $string); $b = explode(' ', $a); return array($b[0] = $b[1]); } maybe just maybe you or I or somebody else can find a way to do this easily in one line; but for now a function similar to above is the best you can do.. Regards Nathan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regular Expression Backreference in subpattern.
On 9/27/08, Nathan Rixham [EMAIL PROTECTED] wrote: Shiplu wrote: The string is tdcharge/tdtd100/td. I want and array( charge=100). I am using this regular expression, '/td([^]+)\/tdtd(?P\1\d+)\/td/'. But its not working.. I get this error., PHP Warning: preg_match(): Compilation failed: syntax error after (?P at offset 25 in E:\src\php\WebEngine\- on line 4 any idea? it seem's everybody is giving you the same answers; here's a definitive look at the problem (as far as I'm aware) all preg_* functions can only return back string's, or array's of strings; there is no method of returning back an associative array as you would like; you can return an array which has friendly name. run the following code, $x = a b;c d;e f;; preg_match('/(?Pkeys\w) (?Pvalues\w)/',$x,$m); print_r($m); allso run this code too for backreference idea, $y = 'a a;b c;d d;e f;f g;h i'; preg_match_all('/(\w) (\1)/',$y,$m); print_r($m); Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu Stop Top Posting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Regular Expression Backreference in subpattern.
Sorry The previous code was wrong, Its the correct version, $x = a b;c d;e f;; preg_match('/(?Pkeys\w) (?Pvalues\w)/',$x,$m); print_r($m); Now I am using backrefrence \1 in in ?P option like (?P\1\d+). and I got the error. -- Blog: http://talk.cmyweb.net/ Follow me: http://twitter.com/shiplu Stop Top Posting. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php