[pmwiki-users] Fixme icon
5ko at 5ko.fr
Sat Jan 11 06:27:12 PST 2020
Based on the cases you listed, you can use this pattern:
$ROEPatterns["/(\\(:FIXME:\\)|(?<![\t])\\bFIXME\\b)/"] = '(:FIXME:)';
Or the same broken into pieces, one with comments:
\\(:FIXME:\\) # existing
| # or
(?<![\t]) # not preceded by tab
\\bFIXME\\b # between non-word characters
)/x"] = '(:FIXME:)';
The word boundary \b already matches start/end of text, newlines and
spaces so you don't need to add these.
The expression has (?<![\t]) -- a rarely used RegEx feature called
negative lookbehind to exclude the "[TAB]FIXME" case. This feature can
only look for strings with fixed length so we need to also find the
existing (:FIXME:) directives in order to not process them.
Alternatively we can test for ":FIXME" which may be part of "(:FIXME:)"
or not. If there are no cases where you need to replace ":FIXME" with
":(:FIXME:)" then the pattern can be simpler:
$ROEPatterns["/(?<![\t:])\\bFIXME\\b/"] = '(:FIXME:)';
that is "FIXME" not part of a word, and not preceded by TAB or colon.
I would advise enabling the "Preview changes" feature and pressing
"Preview" to see how this behaves and to make sure nothing is forgotten
or replaced by mistake.
You can read more about lookahead and lookbehind here:
In case you wonder about the comments in the pattern, the /x modifier or
why the \t is in brackets, see here:
If you upgrade : http://www.pmwiki.org/Upgrades
On 10/01/2020 22:45, Robert Riebisch wrote:
> As I'm not very familiar with RegExp it took my some hours on
> <https://regexr.com/> to create an ROE Pattern to replace FIXME with
> $ROEPatterns['/(^|\\n| )\\b(FIXME)\\b( ?)/'] = '\\1(:\\2:)\\3';
> It seems to work for me now, but is it really right on edge cases?
> My test cases:
> ^^^^^ At the beginning (match:)
> Standalone (match):
> Already replaced (no match):
> In the middle of a word (no match):
> Lowercase (no match):
> Indented by 1 space (match):
> Indented by 2 spaces (match):
> Indented by 1 TAB (no match):
> Indented and followed by spaces (match):
> Somewhere in a text (match):
> Foo FIXME bar.
> End the end (match):
More information about the pmwiki-users