regex!() { /* proc-macro */ }
Expand description

The macro creates a function which returns true if the argument matches the regex.

If the first argument is an identifier (name), then this is the name of the function, which would be generated. Example:

use proc_macro_regex::regex;

regex!(the_name_of_the_function "the regex to check");

Alternative, if the first argument is a visibility keyword, then this is the visibility of the function. Otherwise, the function is private. Example:

regex!(pub public_function "the function is public");
regex!(private_function "the function is private");

The next argument is a string of the regex, which the function should check. Alternative, a byte string can be given, if the input should be a byte array (&[u8]). otherwise a string is taken.

regex!(string_function "This function takes a string");
regex!(bytes_function "This function takes a byte array");

At the end, a positive number can be given to set the limit of the lookup table (see README.md).

regex!(limit_function "The limit is set to 100 bytes" 100);

Syntax

The given regex works the same as in the regex crate.

  • If the ^ is at the beginning of the regex, then it is checked if the input is match at the beginning of the text.
  • If the $ is at the end, then it is checked if the input is match at the end of the text.
  • If both are present then the whole input is checked.
  • Otherwise, is check if the string contains the regex.