Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16110 > unrolled thread
| Started by | "R.Wieser" <address@not.available> |
|---|---|
| First post | 2016-01-06 17:18 +0100 |
| Last post | 2016-01-12 16:11 +0100 |
| Articles | 14 on this page of 114 — 10 participants |
Back to article view | Back to comp.lang.php
parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-06 17:18 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-06 19:28 +0000
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-06 20:50 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-06 21:12 +0000
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-06 16:20 -0500
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 02:23 +0000
Re: parsing print_r() output with preg_match_all() Matthew Carter <m@ahungry.com> - 2016-01-06 21:48 -0500
Re: parsing print_r() output with preg_match_all() Matthew Carter <m@ahungry.com> - 2016-01-06 21:52 -0500
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 10:20 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 10:56 +0000
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 12:55 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 08:36 -0500
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 13:58 +0000
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 15:33 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 15:31 +0000
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 18:23 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-06 22:50 -0500
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 10:10 +0100
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 10:03 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 08:38 -0500
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 14:05 +0000
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 13:42 -0500
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 20:24 +0000
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 15:27 -0500
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 09:51 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 11:18 +0000
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 14:00 +0100
Re: parsing print_r() output with preg_match_all() Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-07 14:00 +0000
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 16:19 +0100
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-11 09:11 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 08:04 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-11 23:48 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-12 00:41 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 20:53 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 05:40 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 09:12 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 21:43 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 16:12 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 22:28 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 16:35 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-13 06:39 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-13 08:26 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 08:10 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-13 14:49 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 10:08 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-13 18:50 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 15:06 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-13 23:11 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 17:18 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-13 23:27 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 19:17 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 01:30 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 20:52 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 08:13 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 09:18 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 20:07 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 16:06 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 22:41 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-14 22:35 +0100
Re: parsing print_r() output with preg_match_all() Ian Collins <ian-news@hotmail.com> - 2016-01-14 10:24 +1300
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 17:20 -0500
Re: parsing print_r() output with preg_match_all() Ian Collins <ian-news@hotmail.com> - 2016-01-14 12:14 +1300
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-13 19:18 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 08:34 +0100
Re: parsing print_r() output with preg_match_all() Anders Wegge Keller <wegge@geostat.dk> - 2016-01-14 09:20 +0100
Re: parsing print_r() output with preg_match_all() Ian Collins <ian-news@hotmail.com> - 2016-01-14 21:56 +1300
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 16:08 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 22:55 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 16:59 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-14 23:09 +0100
Re: parsing print_r() output with preg_match_all() Ian Collins <ian-news@hotmail.com> - 2016-01-15 11:17 +1300
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 19:15 -0500
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-14 19:14 -0500
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 20:50 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 05:42 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-12 08:41 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 09:13 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 21:44 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 16:13 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-12 22:29 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 16:33 -0500
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-12 00:49 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 20:54 -0500
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 11:17 +0100
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 13:49 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 14:20 +0100
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 15:31 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 16:00 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 13:45 -0500
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-07 20:18 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-07 20:52 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-07 15:29 -0500
Re: parsing print_r() output with preg_match_all() Tim Streater <timstreater@greenbee.net> - 2016-01-07 22:42 +0000
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-08 10:43 +0100
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-11 09:07 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 08:05 -0500
Re: parsing print_r() output with preg_match_all() Arno Welzel <usenet@arnowelzel.de> - 2016-01-11 23:51 +0100
Re: parsing print_r() output with preg_match_all() Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-12 00:31 +0100
Re: parsing print_r() output with preg_match_all() Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-11 20:55 -0500
Re: parsing print_r() output with preg_match_all() "R.Wieser" <address@not.available> - 2016-01-12 11:11 +0100
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... "R.Wieser" <address@not.available> - 2016-01-12 11:54 +0100
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-12 11:25 +0000
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... "R.Wieser" <address@not.available> - 2016-01-12 13:41 +0100
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-01-12 14:11 +0100
Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... "R.Wieser" <address@not.available> - 2016-01-12 14:34 +0100
Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-01-12 15:03 +0100
Re: parsing print_r() output with preg_match_all() - questionremainsunanswered ... "R.Wieser" <address@not.available> - 2016-01-12 15:50 +0100
Re: parsing print_r() output with preg_match_all() - questionremainsunanswered ... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-01-12 16:36 +0100
Re: parsing print_r() output with preg_match_all() - Solved. "R.Wieser" <address@not.available> - 2016-01-12 21:28 +0100
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-01-12 14:02 +0000
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-01-12 12:42 +0100
Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... "R.Wieser" <address@not.available> - 2016-01-12 14:20 +0100
Re: parsing print_r() output with preg_match_all() - question remains unanswered ... Jerry Stuckle <jstucklex@attglobal.net> - 2016-01-12 09:43 -0500
Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... "R.Wieser" <address@not.available> - 2016-01-12 16:11 +0100
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 11:54 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <5694daea$0$23814$e4fe514c@news.xs4all.nl> |
| In reply to | #16200 |
People, Although this thread has gotten quite a number of posts, I've not seen any attempt to respond to my question : How do I get preg_match_all() to accept an "or" in the pattern (ok, this is not that hard) *and* put the result in the "match" array in the order they are found in (this one stumps me). Look at the example print_r() output I've provided. I both need the closing brackets as well as the parts of the "[....] => ...." lines. *And* I need to find them in the "match" array in the sequence they are appearing in the file. If that is not done than the "match" array becomes worthless to me (due to the captured parts than appearing "out of sync" in relation to each other). For clarity: I do not need a(nother) post telling me I should not want to try that on the input I've provided, I'm simply asking if its possible to do so, and if so how. If it makes it any easier, just imagine I never mentioned print_r() nor provided the to-be-read structure as an example. :-) Regards, Rudy Wieser P.s. I already have a working version for parsing the (simple, strings only) output of print_r() (which uses explode() and preg_match() ). So if there is no answer that will not be a problem. But I would like to know if its at all possible, so I can, in a future case, use the command to its fullest. -- Origional message: R.Wieser <address@not.available> schreef in berichtnieuws 5694d0c2$0$23771$e4fe514c@news.xs4all.nl... > Arno, > > > Where did the *quoted* posting say it has to be human readable? > > That would be my second post (first reply), where I, in the first line of > the first paragraph, said: > > "I'm using it to store the array-of-arrays into a file in human-readable > format." > > I did have a look at (de)serializing. As I already assumed and mentioned to > ben as such, its not really ment to be read or altered by humans ... > > Regards, > Rudy Wieser > > > -- Origional message > Arno Welzel <usenet@arnowelzel.de> schreef in berichtnieuws > 56943207.1060207@arnowelzel.de... > > Jerry Stuckle schrieb am 2016-01-11 um 14:05: > > > > > On 1/11/2016 3:07 AM, Arno Welzel wrote: > > >> R.Wieser schrieb am 2016-01-06 um 17:18: > > >> > > >>> I'm saving the contents of an array-of-arrays into a string with > print_r(). > > >>> Now I want to parse the contents of that string into an > array-of-arrays > > >>> again. > > >> > > >> It's way easier to use serialize() and unserialize() for this purpose: > > >> > > >> <http://php.net/manual/en/function.serialize.php> > > >> <http://php.net/manual/en/function.unserialize.php> > > >> > > >> > > >> > > > > > > He said it had to be human readable, and has already discarded > > > serializing the data. I guess you have trouble reading, also. > > > > Where did the *quoted* posting say it has to be human readable? > > > > > > -- > > Arno Welzel > > http://arnowelzel.de > > http://de-rec-fahrrad.de > > http://fahrradzukunft.de > >
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-01-12 11:25 +0000 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <87si23ujik.fsf@bsb.me.uk> |
| In reply to | #16201 |
"R.Wieser" <address@not.available> writes:
<snip>
> Although this thread has gotten quite a number of posts, I've not seen any
> attempt to respond to my question :
>
> How do I get preg_match_all() to accept an "or" in the pattern (ok, this is
> not that hard) *and* put the result in the "match" array in the order they
> are found in (this one stumps me).
I image that's because the problem was tied up with a task that most
people thought should be abandoned and the specific example was rather
fiddly. The question, as above, sounds odd because if I do this:
$s = "one, two, two, three, one";
preg_match_all('/one|two/', $s, $m);
var_dump($m);
I get the matches in order. Maybe you should start with a simpler
example like this to explain what's not happening as you'd like? There
will be something about the way you use () and (?:) that needs to be
adjusted, but it will be simpler to diagnose in as uncluttered an
example as possible.
<snip>
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 13:41 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <5694f3d9$0$23849$e4fe514c@news.xs4all.nl> |
| In reply to | #16202 |
Ben ,
> The question, as above, sounds odd because if I do this:
>
> $s = "one, two, two, three, one";
> preg_match_all('/one|two/', $s, $m);
> var_dump($m);
>
> I get the matches in order.
Now imagine that the words "one" and "two" are actually two (or more) word
phrases. Something like this perhaps:
$s = "the quick ". "\r\n" . " brown fox";
preg_match_all('/the quick|brown fox/m', $s, $m);
Would the OR affect only the words "quick" and "brown", or does it go for
the whole phrase left and right of the OR symbol ? AFAIK and experience
tells me its the former. So, how do I group words and symbols together in
the above pattern, so I can match the full phrases left and right of that OR
symbol.
I can't use "(" and ")", as anything between them seems to be stored in the
"match" array. Curly or straight brackets do not work (I already tried).
Making it one step more difficult, how can I pre/append parts that that must
be true for both patterns -- think of the start and end of line symbols, and
maybe some whit-space gobbling stuff too.
To make it absolute simple and clear: How do I combine
"^\s+the quick\s+$"
and
"^\s+brown fox\s+$"
into a single match (preferrably seeing the "^\s+" and "\s+$" parts only
once).
And than the problem of caturing a different number of results from the
above phrases comes into play : Both "the" and "quick" from the in the first
pattern ("^\s+(the) (quick)\s+$" ) and only "brown" from the latter
("^\s+brown (fox)\s+$").
Something like this (using "<" and ">" to indicate grouping):
"^\s+<<(the) (quick)>|<(brown) fox>>\s+$"
Also, all the columns of the "match" array need to have the same number of
entries. Maybe even by adding a dummy captures. Like this perhaps :
"^\s+<<(the) (quick)>|<(brown) fox()>>\s+$"
Does that clarify it ? (it certainly doesn't make it easier :-) )
Regards,
Rudy Wieser
-- Origional message:
Ben Bacarisse <ben.usenet@bsb.me.uk> schreef in berichtnieuws
87si23ujik.fsf@bsb.me.uk...
> "R.Wieser" <address@not.available> writes:
> <snip>
> > Although this thread has gotten quite a number of posts, I've not seen
any
> > attempt to respond to my question :
> >
> > How do I get preg_match_all() to accept an "or" in the pattern (ok, this
is
> > not that hard) *and* put the result in the "match" array in the order
they
> > are found in (this one stumps me).
>
> I image that's because the problem was tied up with a task that most
> people thought should be abandoned and the specific example was rather
> fiddly. The question, as above, sounds odd because if I do this:
>
> $s = "one, two, two, three, one";
> preg_match_all('/one|two/', $s, $m);
> var_dump($m);
>
> I get the matches in order. Maybe you should start with a simpler
> example like this to explain what's not happening as you'd like? There
> will be something about the way you use () and (?:) that needs to be
> adjusted, but it will be simpler to diagnose in as uncluttered an
> example as possible.
>
> <snip>
> --
> Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2016-01-12 14:11 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <n72u2h$3va$1@solani.org> |
| In reply to | #16204 |
R.Wieser wrote:
> Now imagine that the words "one" and "two" are actually two (or more) word
> phrases. Something like this perhaps:
>
> $s = "the quick ". "\r\n" . " brown fox";
> preg_match_all('/the quick|brown fox/m', $s, $m);
>
> Would the OR affect only the words "quick" and "brown", or does it go for
> the whole phrase left and right of the OR symbol ? AFAIK and experience
> tells me its the former. So, how do I group words and symbols together in
> the above pattern, so I can match the full phrases left and right of that OR
> symbol.
This regular expression matches either "the quick" or "brown fox".
However, as the regex is not anchored, it also matches "the brown fox",
for instance.
> I can't use "(" and ")", as anything between them seems to be stored in the
> "match" array. Curly or straight brackets do not work (I already tried).
You can use non-capturing subexpressions[1] to group arbitrarily, e.g.
preg_match('/^the (?:quick/brown) fox$/', $s, $m)
matches either "the quick fox" or "the brown fox".
> And than the problem of caturing a different number of results from the
> above phrases comes into play : Both "the" and "quick" from the in the first
> pattern ("^\s+(the) (quick)\s+$" ) and only "brown" from the latter
> ("^\s+brown (fox)\s+$").
Well, just try the following:
preg_match_all("/^\s+(?:(the) (quick)|brown (fox))\s+$/", $s, $m)
Set $s = ' the quick ' and ' brown fox ', respectively, and then inspect
$m. In the first case, $m[3] is empty, in the second case $m[1] and
$m[2] are empty, so you can distinguish between both cases by checking
these conditions.
Using named subpatterns might simplify the logic.
[1] <http://php.net/manual/en/regexp.reference.subpatterns.php>
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 14:34 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... |
| Message-ID | <56950070$0$23766$e4fe514c@news.xs4all.nl> |
| In reply to | #16205 |
Christoph,
First off, thanks for the explanation.
> However, as the regex is not anchored, it also matches
> "the brown fox", for instance
"not anchored" ? Can you explain what you mean with that please ? I do
not quite understand how the pattern could both match "the fox" as well as
"the brown fox" (and presumably "the quick fox" too). I took it as given
*all* words need to appear in the text (in the correct order) for a pattern
to match it (only one of an ORed set ofcourse).
Remark: I'm not a regex expert. Rather, I'm one of those people who thinks
of using a regex to solve a problem, only than to be stuck with two problems
instead :-)
Regards,
Rudy Wieser
-- Origional message:
Christoph M. Becker <cmbecker69@arcor.de> schreef in berichtnieuws
n72u2h$3va$1@solani.org...
> R.Wieser wrote:
>
> > Now imagine that the words "one" and "two" are actually two (or more)
word
> > phrases. Something like this perhaps:
> >
> > $s = "the quick ". "\r\n" . " brown fox";
> > preg_match_all('/the quick|brown fox/m', $s, $m);
> >
> > Would the OR affect only the words "quick" and "brown", or does it go
for
> > the whole phrase left and right of the OR symbol ? AFAIK and
experience
> > tells me its the former. So, how do I group words and symbols together
in
> > the above pattern, so I can match the full phrases left and right of
that OR
> > symbol.
>
> This regular expression matches either "the quick" or "brown fox".
> However, as the regex is not anchored, it also matches "the brown fox",
> for instance.
>
> > I can't use "(" and ")", as anything between them seems to be stored in
the
> > "match" array. Curly or straight brackets do not work (I already
tried).
>
> You can use non-capturing subexpressions[1] to group arbitrarily, e.g.
>
> preg_match('/^the (?:quick/brown) fox$/', $s, $m)
>
> matches either "the quick fox" or "the brown fox".
>
> > And than the problem of caturing a different number of results from the
> > above phrases comes into play : Both "the" and "quick" from the in the
first
> > pattern ("^\s+(the) (quick)\s+$" ) and only "brown" from the latter
> > ("^\s+brown (fox)\s+$").
>
> Well, just try the following:
>
> preg_match_all("/^\s+(?:(the) (quick)|brown (fox))\s+$/", $s, $m)
>
> Set $s = ' the quick ' and ' brown fox ', respectively, and then inspect
> $m. In the first case, $m[3] is empty, in the second case $m[1] and
> $m[2] are empty, so you can distinguish between both cases by checking
> these conditions.
>
> Using named subpatterns might simplify the logic.
>
> [1] <http://php.net/manual/en/regexp.reference.subpatterns.php>
>
> --
> Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2016-01-12 15:03 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... |
| Message-ID | <n7312g$f8i$1@solani.org> |
| In reply to | #16207 |
R.Wieser wrote:
> Christoph,
>
> First off, thanks for the explanation.
You're welcome.
>> However, as the regex is not anchored, it also matches
>> "the brown fox", for instance
>
> "not anchored" ? Can you explain what you mean with that please ?
Anchors are assertions about the position of a matching point. For
instance, ^ at the beginning and $ at the end of a pattern make sure
that the complete subject string has to match.
> I do
> not quite understand how the pattern could both match "the fox" as well as
> "the brown fox" (and presumably "the quick fox" too). I took it as given
> *all* words need to appear in the text (in the correct order) for a pattern
> to match it (only one of an ORed set ofcourse).
Indeed, "all words need to appear in the text (in the correct order)",
but without anchors, additional "words" may appear in the text. Compare
preg_match('/the quick|brown fox/m', 'the brown fox');
vs.
preg_match('/^(?:the quick|brown fox)$/m', 'the brown fox');
The former returns 1 (i.e. matches), while the latter returns 0 (i.e.
doesn't match). That is because the first preg_match() is content to
match only part of the subject string.
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 15:50 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - questionremainsunanswered ... |
| Message-ID | <5695123f$0$23795$e4fe514c@news.xs4all.nl> |
| In reply to | #16209 |
Christoph,
> Anchors are assertions about the position of a matching point.
Ah, ofcourse. I was thinking of the example I gave, and forgot to think
outside of it.
From what you wrote I think my conclude that OR-ing only affects the
words/symbols directly next to it, *unless* it appears inside a "(?", ")"
grouping, in which case the whole subphrase must match.
Regards,
Rudy Wieser
-- Origional message:
Christoph M. Becker <cmbecker69@arcor.de> schreef in berichtnieuws
n7312g$f8i$1@solani.org...
> R.Wieser wrote:
>
> > Christoph,
> >
> > First off, thanks for the explanation.
>
> You're welcome.
>
> >> However, as the regex is not anchored, it also matches
> >> "the brown fox", for instance
> >
> > "not anchored" ? Can you explain what you mean with that please ?
>
> Anchors are assertions about the position of a matching point. For
> instance, ^ at the beginning and $ at the end of a pattern make sure
> that the complete subject string has to match.
>
> > I do
> > not quite understand how the pattern could both match "the fox" as well
as
> > "the brown fox" (and presumably "the quick fox" too). I took it as
given
> > *all* words need to appear in the text (in the correct order) for a
pattern
> > to match it (only one of an ORed set ofcourse).
>
> Indeed, "all words need to appear in the text (in the correct order)",
> but without anchors, additional "words" may appear in the text. Compare
>
> preg_match('/the quick|brown fox/m', 'the brown fox');
>
> vs.
>
> preg_match('/^(?:the quick|brown fox)$/m', 'the brown fox');
>
> The former returns 1 (i.e. matches), while the latter returns 0 (i.e.
> doesn't match). That is because the first preg_match() is content to
> match only part of the subject string.
>
> --
> Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2016-01-12 16:36 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - questionremainsunanswered ... |
| Message-ID | <n736i6$46k$1@solani.org> |
| In reply to | #16216 |
R.Wieser wrote:
> From what you wrote I think my conclude that OR-ing only affects the
> words/symbols directly next to it, *unless* it appears inside a "(?", ")"
> grouping, in which case the whole subphrase must match.
Actually, | has a low precedence, similar to the PHP || operator. The
following example illustrates that:
preg_match('/^one|two$/', $s)
This function call returns 1, if $s is "one foo" or "foo two", for
instance. So even the anchors ^ and $ have higher precedence than the |
(so to say). If only "one" or "two" should be matched, you've had to use
preg_match('/^(one|two)$/', $s)
--
Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 21:28 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - Solved. |
| Message-ID | <5695617a$0$23747$e4fe514c@news.xs4all.nl> |
| In reply to | #16218 |
Christoph,
> If only "one" or "two" should be matched, you've had to use
>
> preg_match('/^(one|two)$/', $s)
Well, that was part of the problem: In someones infinite wisdom those round
brackets are used both to group stuff as well as being indicators to which
part(s) of the found pattern should be stored into the "match" array.
I got all sorts of interresting (but quite useless) results in that "match"
array while trying to figure out how the grouping and capturing works. I
failed at that, until you posted that link of yours.
Regards,
Rudy Wieser
P.s.
Hmmm ... Forgot to change the subject line to "solved". Done now.
-- Origional message:
Christoph M. Becker <cmbecker69@arcor.de> schreef in berichtnieuws
n736i6$46k$1@solani.org...
> R.Wieser wrote:
>
> > From what you wrote I think my conclude that OR-ing only affects the
> > words/symbols directly next to it, *unless* it appears inside a "(?",
")"
> > grouping, in which case the whole subphrase must match.
>
> Actually, | has a low precedence, similar to the PHP || operator. The
> following example illustrates that:
>
> preg_match('/^one|two$/', $s)
>
> This function call returns 1, if $s is "one foo" or "foo two", for
> instance. So even the anchors ^ and $ have higher precedence than the |
> (so to say). If only "one" or "two" should be matched, you've had to use
>
> preg_match('/^(one|two)$/', $s)
>
> --
> Christoph M. Becker
>
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-01-12 14:02 +0000 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <87mvsavqu4.fsf@bsb.me.uk> |
| In reply to | #16204 |
"R.Wieser" <address@not.available> writes:
[You've omitted attribution lines.]
>> The question, as above, sounds odd because if I do this:
>>
>> $s = "one, two, two, three, one";
>> preg_match_all('/one|two/', $s, $m);
>> var_dump($m);
>>
>> I get the matches in order.
>
> Now imagine that the words "one" and "two" are actually two (or more) word
> phrases.
<snip more>
I was about to answer you specific points when I saw you have an overall
answer. If there are any outstanding detail I'll have a go at answering
but it seems pointless to go through your questions otherwise.
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2016-01-12 12:42 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <n72oqj$g3h$1@solani.org> |
| In reply to | #16201 |
R.Wieser wrote: > How do I get preg_match_all() to accept an "or" in the pattern (ok, this is > not that hard) *and* put the result in the "match" array in the order they > are found in (this one stumps me). Perhaps using named subpatterns might be helpful in this case, see <http://php.net/manual/en/regexp.reference.subpatterns.php>. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 14:20 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... |
| Message-ID | <5694fd33$0$23774$e4fe514c@news.xs4all.nl> |
| In reply to | #16203 |
Christoph, > Perhaps using named subpatterns might be helpful in this case, see > <http://php.net/manual/en/regexp.reference.subpatterns.php>. It certainly does ! It also solves the riddle of how grouping symbols need to be written down ... Never would have guessed it. Thanks. :-) The pattern '/^\s+(?|\[(.*)\] => (.*)|(\)))$/m' now generates matches on both " [....] => ..." and " )", *and* stores it into the "match" array in three columns of an equal length. Regards, Rudy Wieser -- Origional message: Christoph M. Becker <cmbecker69@arcor.de> schreef in berichtnieuws n72oqj$g3h$1@solani.org... > R.Wieser wrote: > > > How do I get preg_match_all() to accept an "or" in the pattern (ok, this is > > not that hard) *and* put the result in the "match" array in the order they > > are found in (this one stumps me). > > Perhaps using named subpatterns might be helpful in this case, see > <http://php.net/manual/en/regexp.reference.subpatterns.php>. > > -- > Christoph M. Becker >
[toc] | [prev] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2016-01-12 09:43 -0500 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remains unanswered ... |
| Message-ID | <n7338v$cra$1@jstuckle.eternal-september.org> |
| In reply to | #16201 |
On 1/12/2016 5:54 AM, R.Wieser wrote:
> People,
>
> Although this thread has gotten quite a number of posts, I've not seen any
> attempt to respond to my question :
>
> How do I get preg_match_all() to accept an "or" in the pattern (ok, this is
> not that hard) *and* put the result in the "match" array in the order they
> are found in (this one stumps me).
>
> Look at the example print_r() output I've provided. I both need the
> closing brackets as well as the parts of the "[....] => ...." lines. *And*
> I need to find them in the "match" array in the sequence they are appearing
> in the file. If that is not done than the "match" array becomes worthless to
> me (due to the captured parts than appearing "out of sync" in relation to
> each other).
>
> For clarity: I do not need a(nother) post telling me I should not want to
> try that on the input I've provided, I'm simply asking if its possible to do
> so, and if so how. If it makes it any easier, just imagine I never
> mentioned print_r() nor provided the to-be-read structure as an example. :-)
>
> Regards,
> Rudy Wieser
>
> P.s.
> I already have a working version for parsing the (simple, strings only)
> output of print_r() (which uses explode() and preg_match() ). So if there
> is no answer that will not be a problem. But I would like to know if its
> at all possible, so I can, in a future case, use the command to its fullest.
>
>
Rudy,
You probably didn't get good answers because most of us think you're
asking the wrong question. You want the output to be both machine and
human readable. That's fine.
However, the output of print_r() is not standardized, and what works
today may not work with a PHP update. That leaves you right back where
you started from.
Additionally, I don't think there is a single regex which will do what
you want, but I'm also far from a regex expert.
JSON is a possibility, but it's not always easy to understand if you
don't already know what you're looking at. Maybe an easier method would
be to write it out in your own format and read it back in. It doesn't
have to be complicated, and can be done with recursive functions.
Something like:
item0|0|key0_0_0|Value_0_0_0
item0|0|key0_0_1|Value_0_0_1
item0|1|key0_1_0|Value_0_1_0
item1|0|key1_1_0|Value_1_1_0
etc. The biggest problem would be to determine which character to use
as a separator ('|' in this case) that's not used in the data. Remember
you can use chars such as tab ('\t'), also. And if that's too hard, you
could escape the separator character in your data, but that makes it
harder to parse.
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | "R.Wieser" <address@not.available> |
|---|---|
| Date | 2016-01-12 16:11 +0100 |
| Subject | Re: parsing print_r() output with preg_match_all() - question remainsunanswered ... |
| Message-ID | <5695170d$0$23764$e4fe514c@news.xs4all.nl> |
| In reply to | #16215 |
Jerry,
> You probably didn't get good answers because most of us
> think you're asking the wrong question.
I'm always open to suggestions ...
> However, the output of print_r() is not standardized, and
> what works today may not work with a PHP update.
I already noticed that the example code I found worked on the assumption of
indentation being done with TAB characters, where my version of PHP uses
SPACE chars. Hence my searching for another solution, for which I needed
those closing brackets.
But yes, my solution would be version specific. Which, in my case, is not
really a problem.
> Additionally, I don't think there is a single regex which will
> do what you want, but I'm also far from a regex expert.
:-) As you probably have already guessed, neither am I. But I got some help
from Christoph M. Becker, who pointed me to
<http://php.net/manual/en/regexp.reference.subpatterns.php>. In short, it's
possible.
Thanks for your help.
Regards,
Rudy Wieser
.
-- Origional message:
Jerry Stuckle <jstucklex@attglobal.net> schreef in berichtnieuws
n7338v$cra$1@jstuckle.eternal-september.org...
> On 1/12/2016 5:54 AM, R.Wieser wrote:
> > People,
> >
> > Although this thread has gotten quite a number of posts, I've not seen
any
> > attempt to respond to my question :
> >
> > How do I get preg_match_all() to accept an "or" in the pattern (ok, this
is
> > not that hard) *and* put the result in the "match" array in the order
they
> > are found in (this one stumps me).
> >
> > Look at the example print_r() output I've provided. I both need the
> > closing brackets as well as the parts of the "[....] => ...." lines.
*And*
> > I need to find them in the "match" array in the sequence they are
appearing
> > in the file. If that is not done than the "match" array becomes
worthless to
> > me (due to the captured parts than appearing "out of sync" in relation
to
> > each other).
> >
> > For clarity: I do not need a(nother) post telling me I should not want
to
> > try that on the input I've provided, I'm simply asking if its possible
to do
> > so, and if so how. If it makes it any easier, just imagine I never
> > mentioned print_r() nor provided the to-be-read structure as an example.
:-)
> >
> > Regards,
> > Rudy Wieser
> >
> > P.s.
> > I already have a working version for parsing the (simple, strings only)
> > output of print_r() (which uses explode() and preg_match() ). So if
there
> > is no answer that will not be a problem. But I would like to know if
its
> > at all possible, so I can, in a future case, use the command to its
fullest.
> >
> >
>
> Rudy,
>
> You probably didn't get good answers because most of us think you're
> asking the wrong question. You want the output to be both machine and
> human readable. That's fine.
>
> However, the output of print_r() is not standardized, and what works
> today may not work with a PHP update. That leaves you right back where
> you started from.
>
> Additionally, I don't think there is a single regex which will do what
> you want, but I'm also far from a regex expert.
>
> JSON is a possibility, but it's not always easy to understand if you
> don't already know what you're looking at. Maybe an easier method would
> be to write it out in your own format and read it back in. It doesn't
> have to be complicated, and can be done with recursive functions.
> Something like:
>
> item0|0|key0_0_0|Value_0_0_0
> item0|0|key0_0_1|Value_0_0_1
> item0|1|key0_1_0|Value_0_1_0
> item1|0|key1_1_0|Value_1_1_0
>
> etc. The biggest problem would be to determine which character to use
> as a separator ('|' in this case) that's not used in the data. Remember
> you can use chars such as tab ('\t'), also. And if that's too hard, you
> could escape the separator character in your data, but that makes it
> harder to parse.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================
[toc] | [prev] | [standalone]
Page 6 of 6 — ← Prev page 1 2 3 4 5 [6]
Back to top | Article view | comp.lang.php
csiph-web