Jump to content

POISEX Regex Assistance


maxudaskin

Recommended Posts

I'm looking to find a a starting and ending phrase and return the text in between.

 

%\{\{items\}\}(.*?)\{\{\/items\}\}%

 

I'm looking for {{items}} and {{/items}}. Anything in between, possibly multiple lines, should be returned ($1?).

 

For some reason, it returns 0 results with the following...

 

<div id="items">

{{items}}

<div class="item">

<table>

<tr>

<td>{{item_number}}</td>

<td class="text_right">{{currency}} {{item_extension}}</td>

</tr>

<tr>

<td colspan="2">{{item_units}} at {{item_cost_per_unit}}</td>

</tr>

</table>

{{item_description}}

</div>

{{/items}}

</div>

Link to comment
https://forums.phpfreaks.com/topic/266794-poisex-regex-assistance/
Share on other sites

dot-all (a period) normally doesn't match newline characters.

 

POSIX you say? Then that means you're using the ereg family of functions. Those are deprecated; you should be using the PCRE functions.

preg_match_all('%\{\{items\}\}(.*?)\{\{/items\}\}%s', $text, $matches);

The /s flag (or in this case %s) is what tells preg_match_all() that the dot-all should include newlines.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.