[pmwiki-users] ROSPatterns/regex question

Peter Kay pkay42 at gmail.com
Tue Sep 26 13:15:40 CDT 2017


ROSPatterns accepts functions - so think "preg_replace_callback()"
instead of "preg_replace".

So something like this might work:

$ROSPatterns[".*"] = "MyRecipeROS"; // process the entire file before saving.

function MyRecipeROS($data) {
  $words=split or preg_split on whitespace, maybe even grab the whitespace;
  $out="";
  for ($i = 0; $i<count($words); $i++) { # might need a different
count if you grabbed the whitespace
    $out.= "(:word_$i $word[$i]:)";//etc etc
  }
  return $out;
}

On Tue, Sep 26, 2017 at 12:44 PM, James DeVain <jamesdevain at mail.com> wrote:
> Hello,
>
> I've been trying to use $ROSPatterns to change something like this:
>
> " mary had a little lamb"
>
> into this:
>
> "(:word_1:mary:)(:word_2:had:)(:word_3:a:)(:word_4:little:)(:word_5:lamb:)"
>
> I don't have much experience with regex, but what I have so far is:
>
> $ROSPatterns ["/^\\s/"]    = "(:w1:";
>
> which places the first "(:word_1:" in front of "mary". Now I need to find the second empty
> space and change it to ":)(:word_2:". I figured I could just write a different ROSPattern
> for each empty space, like:
>
> $ROSPatterns ["/^\\s/"]    = "(:w1:";
> $ROSPatterns ["...find second empty space..."]    = ":)(:w2:";
> $ROSPatterns ["...find third empty space..."]    = ":)(:w3:";
> ... etc.
>
> Everything I've tried either erases everything after the second space, replaces EVERYTHING
> with ":)(:word_2:", has no effect at all, or some other unexpected result.
>
> I realize that this is more of a regex question than a PmWiki question, but if anybody could
> help me with this I would be very grateful.
>
> Thanks!
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://www.pmichaud.com/mailman/listinfo/pmwiki-users



More information about the pmwiki-users mailing list