Trouble with ereg() and matching right bracket "]"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Gangefors

    Trouble with ereg() and matching right bracket "]"

    I'm trying to figure out what I'm doing wrong when using ereg().

    This is my regexp:

    ereg("^[\]]$", "]");

    and that does'n work, but this does:

    ereg("^[\[]$", "[");


    How come I can match left bracket but not the right?
    am I using the esc char correctly?

    please help me.

    regards
    /gange
  • Michael Fuhr

    #2
    Re: Trouble with ereg() and matching right bracket "]"

    gange@elak.org (Stefan Gangefors) writes:
    [color=blue]
    > I'm trying to figure out what I'm doing wrong when using ereg().
    >
    > This is my regexp:
    >
    > ereg("^[\]]$", "]");
    >
    > and that does'n work, but this does:
    >
    > ereg("^[\[]$", "[");
    >
    > How come I can match left bracket but not the right?
    > am I using the esc char correctly?[/color]

    The "Regular Expression Functions (POSIX Extended)" chapter of the
    PHP manual directs readers to the regex manual page in the PHP
    source code. That manual page says:

    "To include a literal `]' in the list, make it the first character
    (following a possible `^'). To include a literal `-', make it the
    first or last character, or the second end- point of a range. To
    use a literal `-' as the first end- point of a range, enclose it
    in `[.' and `.]' to make it a collating element (see below). With
    the exception of these and some combinations using `[' (see next
    paragraphs), all other special characters, including `\', lose their
    special significance within a bracket expression."

    --
    Michael Fuhr

    Comment

    Working...