470,864 Members | 2,023 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,864 developers. It's quick & easy.

How to change PCRE default delimiters

Hello,

I try to use alternative delimiters for a regular expression.
When will it be supported?

www@mike:/home/www > /usr/local/bin/php -a
Interactive mode enabled

<?php
preg_match('m!A(\d*)B!', 'A12345B', $X));
?>
X-Powered-By: PHP/4.2.3
Content-type: text/html

<br />
<b>Parse error</b>: parse error in <b>-</b> on line <b>2</b><br />

http://perldoc.com/perl5.8.4/pod/perlrequick.html

Best regards,
Markus Elfring
Jul 17 '05 #1
5 2581
Markus Elfring wrote:
I try to use alternative delimiters for a regular expression.
When will it be supported?

<?php
preg_match('m!A(\d*)B!', 'A12345B', $X));
?>

<b>Parse error</b>: parse error in <b>-</b> on line <b>2</b><br />


It is supported, but you have one too many brackets on the end of that
line, before the semicolon. That's what's causing the parse error.

--
Jasper Bryant-Greene
Cabbage Promotions
Jul 17 '05 #2
Markus Elfring wrote:
I try to use alternative delimiters for a regular expression.
When will it be supported?
Already is.

| The expression should be enclosed in the delimiters, a
| forward slash (/), for example. Any character can be used
| for delimiter as long as it's not alphanumeric or
| backslash (\). If the delimiter character has to be used
| in the expression itself, it needs to be escaped by
| backslash. Since PHP 4.0.4, you can also use Perl-style
| (), {}, [], and <> matching delimiters.

http://www.php.net/manual/en/ref.pcre.php

[ ... ]
preg_match('m!A(\d*)B!', 'A12345B', $X));

----------------------------------------^^
As someone else said, you've one too many there.

Use '!A(\d*)B!'. No 'm', since this isn't Perl.

[ ... ]

--
Jock
Jul 17 '05 #3
> > preg_match('m!A(\d*)B!', 'A12345B', $X));
----------------------------------------^^
As someone else said, you've one too many there.
Thanks for this hint.
I'm sorry for this nasty typo;

Use '!A(\d*)B!'. No 'm', since this isn't Perl.


Is there missing anything about "pattern delimiters" in the documentation?
http://de.php.net/manual/en/function.preg-match.php
Jul 17 '05 #4
> [ ... ]
| The expression should be enclosed in the delimiters, a
| forward slash (/), for example. Any character can be used
| for delimiter as long as it's not alphanumeric or
| backslash (\). If the delimiter character has to be used
| in the expression itself, it needs to be escaped by
| backslash. Since PHP 4.0.4, you can also use Perl-style
| (), {}, [], and <> matching delimiters.
[ ... ]


It would help if this description from the introduction will be
repeated on more pages for the other functions.
Jul 17 '05 #5
Markus Elfring wrote:

[ Re documentation of PCRE delimiters ]
It would help if this description from the introduction will be
repeated on more pages for the other functions.


Having glanced through the section again, I see where
confusion might arise; though I admit I hadn't noticed
before.

The terms 'pattern', 'regex', 'expression', and 'regular
expression' seem to be used interchangeably. The
introduction to PCREs uses the term 'expression' in the same
sense as 'pattern' is used in the separate section on
'Pattern Syntax'; but in the preg_* function docs, 'pattern'
means an opening delimiter, a pattern proper, an ending
delimiter, plus optional pattern modifiers. With more than
one name for a single thing, and a single name for more than
one thing, mystification comes as no surprise.

I trust you've sorted it out though. ;o)

--
Jock
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by news | last post: by
17 posts views Thread by sgane2001 | last post: by
16 posts views Thread by mainland | last post: by
13 posts views Thread by sonald | last post: by
11 posts views Thread by cybervigilante | last post: by
13 posts views Thread by Wiseman | last post: by
1 post views Thread by moreati | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.