Hello all,
Having some difficulty with what should be a simple regular expression.
I'm trying to check that the following string is in the appropriate format:
Page[page.php]
Should begin with any string of characters, then a '[' then another string, then a closing ']' (with no characters after the closing ']')

So basically wildcard[wildcard]

I think I'm having difficulty escaping the brackets as they are being read as part of the expression.

$pattern = '/s^[s]&/';
$value = 'Page[page.php]';
$match = preg_match($pattern, $value);

Any help very much appreciated.

    See Escape sequences, first paragraph.

    Also, note that [font=monospace]s[/font] doesn't match "any string of characters", it matches the letter 's'; a similar note applies to the ampersand.

      Typo on ampersand, should have been $.
      Escape brackets with backslash (easy enough), using '.' to match all characters to begin string and between [].
      Still can't get a match.

      $pattern = '/.^\[.\]$/'; 
      $value = 'Page[page.php]'; 
      $match = preg_match($pattern, $value); 

      This is a regex problem. I've read up on a few regex resources but haven't found anything to make this click. I can match a type of character, beginning of a string, end of a string, just not clear on the equivalent of a wildcard match between parts of the string.

        The "" is a start-of-string assertion, and as such does not make sense appearing after the first "." character.

          Got it. Thanks guys.

          $pattern = '/.*\[.*.\]$/'; 
          $value = 'Page[page.php]'; 
          $match = preg_match($pattern, $value); 

            Add this to make sure that the string begins with an alphanumeric character.

            $pattern = '/^[a-zA-Z0-9].*\[.*.\]$/'; 
            $value = 'Page[page.php]'; 
            $match = preg_match($pattern, $value);
            
              Write a Reply...