Posted by Amitaibu on October 29, 2007 at 7:34pm
Jump to:
| 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:
/\[(.*?)\s*\=\s*(.*?)\s*\|\s*(.*?)\s*\]/(basically/\[(.*?)\=(.*?)\|(.*?)\]/, but \s* here used to ignore spaces)<a href="$1/$2">$3</a>/\[\s*(.*?)\s*\|\s*(.*?)\s*\]/(basically/\[(.*?)\|(.*?)\]/)<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
I am setting the report as fixed because it got an answer.
#3
#4
Automatically closed -- issue fixed for 2 weeks with no activity.