Template Blocks.

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
Afterlife(69)
Spammer :|
Posts: 14
Joined: Mon Oct 03, 2005 4:51 am

Template Blocks.

Post by Afterlife(69) »

Hi, im making a template system and having a little trouble with the regex.

Code: Select all

$pattern = "|(<!-- START $blkName -->)(.*)(<!-- CLOSE $blkName -->)|";
this is my regex to find the blocks but its not working when i put new lines.

This is the style that won't work.

Code: Select all

<!-- START myBlock -->
	<!-- START nesting.myBlock -->
	Text<br />
	<!-- CLOSE nesting.myBlock -->
<!-- CLOSE myBlock -->
Where if i use this it will.

Code: Select all

<!-- START myBlock --><!-- START nesting.myBlock -->Text<br /><!-- CLOSE nesting.myBlock --><!-- CLOSE myBlock -->
Please reply soon.
~AL69
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your pattern's usage of the any metacharacter does not match across separate lines automatically. Use the s pattern modifier. If you plan to have more than one of these blocks, you may want to also use an ungreedy pattern such as .*? instead of .*
Afterlife(69)
Spammer :|
Posts: 14
Joined: Mon Oct 03, 2005 4:51 am

Post by Afterlife(69) »

Ok, thanks could you just give a little bit of an example of how i would use s im new to regex lol
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply