Grep-Talk
This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.
Is this really php 7.2 compatible? I notice the php code includes Markup_e()
. -- RandyB September 28, 2019, at 02:51 AM
Yes, it really is. When the 4th argument is a function name, Markup_e()
behaves like Markup()
and doesn't call create_function()
, that's what is deprecated since PHP 7.2. I've removed the "_e" to avoid confusion. --Petko September 28, 2019, at 06:01 AM
Hi Petko, thanks for this recipe, I find it very useful. May I ask two things?:
- The upgrade to php 7.2;
- An optional parameter to avoid matching duplicate strings (maybe something like: noduplicate=1)
Thank you.
- Done, thanks for reminding me.
- You can use
limit=1
to replace the first match only (limit=2
for the first two matches, etc.)
Thelimit
argument refers to the total number of replacements, it doesn't remove duplicate results. Let me think about it. --Petko November 02, 2017, at 12:47 AM
My English is not perfect, better if I put an example:
[[#test]] Lorem ipsum dolor sit amet, (APPLE) consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore (PEACH) magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip (APPLE) ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit (PEAR) esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. [[#testend]]
(:grep {*$FullName}#test#testend match=1 self=1 mod=g pat='\((.*?)\)' repl="* $1\n":)
- APPLE
- PEACH
- APPLE
- PEAR
Instead, I need this result:
- APPLE
- PEACH
- PEAR
In version 20171103 I've added the possibility to use a custom function to process the results, see the recipe page. The example function can sort the results and remove duplicates (note that the nodup=1
option as the function is written now will probably sort the results anyway). See array_unique and sort for different flags you can use (case insensitive, numeric, etc.). --Petko November 02, 2017, at 04:16 AM
This solution has solved several problems (... and a headache). Thank you very much.
- can the subject include wildcards? e.g.
Groupn*/Pagen*
- how do I include the entire line the text is found on?
(:grep FixtureCard/{$:Year}* pat='\A||.*(bike|biking|cycle|cycling|mtb).*\Z' repl='$0':)
- No.
- Use "$0\n", or do not use a "repl=" parameter:
List lines containing ".2010": (:grep Cookbook.Grep#news match=1 pat='^.*\.2010.*$':) |
List lines containing ".2010":
|
List lines containing ".2010": (:grep Cookbook.Grep#news match=1 pat='^.*\.2010.*$' repl="$0\n":) |
List lines containing ".2010":
|
To only list lines containing the match (like the unix `grep` utility), include the "match=1" parameter. --Petko May 29, 2016, at 02:35 AM
Hello,
Thanks for this snippet. I'm using it to automatically generate Table of Contents for a page. tkcusr?
I'm using grep here, e.g.
||width=100% ||!Date ||!Trip ||!Activity ||!Leader ||!Phone ||!Book now ||![+[[June]]+] ||-||-|||||| (:grep FixtureCard/{$ThisYear}June pat='.*(?:ski|climb|lodge).*' repl="$0\n" mod=i match=1:) ||! ||-||-|||||| ||![+[[July]]+] ||-||-|||||| (:grep FixtureCard/{$ThisYear}July pat='.*(?:ski|climb|lodge).*' repl="$0\n" mod=i match=1:) ||! ||-||-|||||| ||![+[[August]]+] ||-||-|||||| (:grep FixtureCard/{$ThisYear}August pat='.*(?:ski|climb|lodge).*' repl="$0\n" mod=i match=1:)
It seems to be doing something to the included line that breaks the table markup. (perhaps adding a character?) If anyone has any ideas I'd really appreciate it.
simon
In the remote pages, you had a line outside of a table that contained the word "ski" and it got included. I have modified your directive to this:
(:grep FixtureCard/{$ThisYear}June pat='^\|\|.*(?:ski|climb|lodge).*$' mod=im match=1:) |
That is, only lines starting with "||" and the modifier needs to be "im" for ^,$ to match start and end of line instead of page. --Petko