Re: regular expression problem



condor wrote:
I want to select a text between square brackets. As it may contain
accents and punctuation I try to use the negation:

"\[([^\]])\]"

However, this does not work and the problem is with the closing square
bracket ("]").

My questions are:
- Is "\]" some reserved sequence with a special meaning.
- if so, how can I work around that and still get functionality I want

Something like this?
<?php
$tests[] = "[this is a test]";
$tests[] = "[Who's life is it anyway?]";

$pat = "[[](.*)[]]";

foreach( $tests as $test ) {
$matched = ereg($pat, $test, $match);
printf("test = '%s', pattern = '%s', match = '%s'\n",
$test, $pat, $match[1]);
}
?>

-david-

.



Relevant Pages

  • Re: regular expression problem
    ... accents and punctuation I try to use the negation: ... this does not work and the problem is with the closing square ... bracket. ...
    (php.general)
  • Re: regular expression problem
    ... accents and punctuation I try to use the negation: ... this does not work and the problem is with the closing square ... bracket. ...
    (php.general)
  • Re: Strange login message (-bash: [: missing `])
    ... mirek wrote: ... There needs to be a space between the directories and the closing square ... bracket. ... JohnK ...
    (alt.os.linux.suse)