How do I match a square bracket literal using RegEx?

前端 未结 6 1940
灰色年华
灰色年华 2021-02-07 00:27

What\'s the regex to match a square bracket? I\'m using \\\\] in a pattern in eregi_replace, but it doesn\'t seem to be able to find a ]..

6条回答
  •  死守一世寂寞
    2021-02-07 01:08

    You don't need to escape it: if isolated, a ] is treated as a regular character.
    Tested with eregi_replace and preg_replace.

    [ is another beast, you have to escape it. Looks like single and double quotes, single or double escape are all treated the same by PHP, for both regex families.

    Perhaps your problem is elsewhere in your expression, you should give it in full.

提交回复
热议问题