View Single Post
  #7 (permalink)  
Old Apr 24th, 2008, 08:44
spinal007's Avatar
spinal007 spinal007 is offline
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,620
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: regexp find and seperate custom tags in a string

I have my own CMS and I use custom tags much more complicated than that - with properties and other rubbish. I can help you make this work.

Firstly, \s = all white space, including \r \n \t and so on. I can only assume whoever suggested you try that alternative doesn't have much experience with reg exp.

Secondly, you keep playing with your switches, but do you actually know what they mean? First you had, /mg, then you tried /i.
/i = ignore case
/g = global match (finds as many matches as possible)
/ig = ignore case & global match
I have never seen or heard of /m. I left the /m switch in my suggestion because I didn't know (and still don't know) what platform you're working on, but I guess /m may be the problem.

Problems I found in your regexp:
- \d will only matche DIGITS, not letters. it would match startcontent_1234 but not startcontent_hello.
- you had a / before the end }}, so you were actually searching for {{startcontent_1234/}}

So here's my revised suggestion:
- [\s\S]*? - lazy match anything between tags (this will work)
- escape all literal symbols such as {, }, / and _ (to make sure)
- /ig switch (to make sure)
- use \w instead of \d

Code: Select all
/\{\{startcontent\_/\w{2,50}\}\}([\s\S]*?)\{\{endcontent\_/\w{2,50}\}\}$/ig

Last edited by spinal007; Apr 24th, 2008 at 08:47.
Reply With Quote