[pmwiki-users] Regex help (excluding spaces)

Petko Yotov 5ko at 5ko.fr
Sat Mar 9 15:40:31 CST 2013

Eric Forgeot writes:
>   Markup ('txt2tags_bold', 'directives', '/\*\*(.*?)\*\*/', "'''$1'''");
> It works but I get wrong output when having for example **this and **this,  
> because this kind of text is not supposed to be marked as bold.  (**this  
> and** should be bold on the other hand)
> So I modified my rule this way, to exclude white spaces before or after:
>     Markup ('txt2tags_bold'     , 'directives', '/\*\*[^\s](.*?)[^\s] 
> \*\*/'       , "'''$1'''");
> Now it almost works, **this and **this are not catched, but the bold parts  
> are not correct, the first and last letters are striped out, for example  
> **another** would become nothe (in bold). Do you know why, and how to  
> correct this?

You need to place the parentheses around everything that is meant to be  
bold, for example '/\*\*([^\s].*?[^\s])\*\*/' .

However, this will not allow you a single bold character. This one will:


This means :
  - starts with a '**'
  - opening the first matched pattern (
  - then a non-whitespace-character \\S, same as [^\\s]
  - opening a second pattern (
    - .* anything, ending with a non-whitespace-character \\S
    - closing the second pattern )
    - the ? after the ) means the pattern is optional
  - closing the first matching pattern )
  - once again '**'.

This is fun :-)


More information about the pmwiki-users mailing list