Project:Custom filter
Version:5.x-1.x-dev
Component:Miscellaneous
Category:support request
Priority:minor
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hi,
No match to your Regex skills. Actually I'm not a developer ;)

1. I'd like to replace [piece| Lorem Ipsum] with <div class="piece">Lorem Ipsum</div>
2. Replace [node=120| Lorem Ipsum] with <a href="/node/120">Lorem Ipsum</a>

Comments

#1

Try this:

  1. For [node=120| Lorem Ipsum]:
    • Pattern: /\[(.*?)\s*\=\s*(.*?)\s*\|\s*(.*?)\s*\]/ (basically /\[(.*?)\=(.*?)\|(.*?)\]/, but \s* here used to ignore spaces)
    • Replacement (no php): <a href="$1/$2">$3</a>
  2. For [piece| Lorem Ipsum]:
    • Pattern: /\[\s*(.*?)\s*\|\s*(.*?)\s*\]/ (basically /\[(.*?)\|(.*?)\]/)
    • Replacement (no php): <div class="$1">$2</div>

And make sure 2 weights more than 1.

We should use \ in front of characters [, ], |, because if not, these characters are used by regex for a special purpose. And (.*?) means, "match any character (except newline)". Every character matched within parenthesis can be retrieved by mentioning $n: $1 for first parenthesis, $2 for the second, and so on. $0 is the whole string matched.

#2

Status:active» fixed

I am setting the report as fixed because it got an answer.

#3

Title:some regex help» Regular expressions help

#4

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.