Jump to content

Only matching a pipe character once


Dead6re

Recommended Posts

\|(?=[^{}]*})

 

Although I suspect your question is a different one than that.

 

$this->contents = preg_replace_callback('/\{([^}]*)\}/', array($Template, 'replace'), $this->contents);

 

then in replace($match):

 

$matches=explode('|',$match[1]);

loop through each $matches to do your replacements.

Link to comment
Share on other sites

Okay, I think I need to explain a bit more.

 

I have a template class in PHP that should replace values within {} brackets.

Inside those brackets, the characters A-z, 0-9, Hyphen (-), Pipe (|), Comma (,), Full-stop (.) & Forward Slash (/).

 

Using the expression tester here using my expression it works: http://www.gskinner.com/RegExr/

However using it in PHP does not.

 

For some reason matching {} brackets from my file does not work.

It seems that having a range of A-z 0-9 matches more than one character

However matching a special character seems to match it once and not more.

 

e.g. It should match all expressions within the {} brackets below [in navy] (Simple HTML)

 

<html>

<head>

<title>{title}</title>

{css|style.css,layout.css}

</head>

<body>

{hyperlink|ahref|text}{randomtext}

</body>

</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.