https://github.com/michaelrsweet/abnf
ABNF to REGEX Library
https://github.com/michaelrsweet/abnf
abnf abnf-regex php regular-expression
Last synced: about 1 year ago
JSON representation
ABNF to REGEX Library
- Host: GitHub
- URL: https://github.com/michaelrsweet/abnf
- Owner: michaelrsweet
- License: mit
- Created: 2017-02-27T14:39:41.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-27T17:32:41.000Z (over 1 year ago)
- Last Synced: 2025-04-09T16:16:56.138Z (about 1 year ago)
- Topics: abnf, abnf-regex, php, regular-expression
- Language: PHP
- Homepage: https://michaelrsweet.github.io/abnf
- Size: 22.5 KB
- Stars: 19
- Watchers: 3
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ABNF to REGEX Library
The ABNF to REGEX library is a pair of PHP functions that validate standard
ABNF (RFC 5234) input and generate POSIX and Perl-compatible regular
expressions for use in schema and applications.
I provide an online form front-end for these functions at:
http://abnf.msweet.org/
The file "example.php" shows how to implement your own web form.
## Functions
### abnf_load(string)
This function parses the ABNF contained in the supplied string. On success, it
returns an array of rules that can be passed to the "abnf_regex" function.
FALSE is returned on failure, with the following global variables describing
the issue:
- "abnf_error" contains a string describing the issue.
- "abnf_errorline" contains the line number in the string where the issue occurred.
- "abnf_errorcol" contains the column number in the string where the issue occurred.
### abnf_regex(rules, rulename, mode = ABNF_INSENSITIVE)
This function generates a regular expression for the named rule. If the named
rule does not exist, an empty string is returned.
The "mode" parameter can be any of the following constants:
- ABNF_INSENSITIVE : Generates a case-insensitive regular expression.
- ABNF_SENSITIVE : Generates a case-sensitive regular expression.
- ABNF_LOWERCASE : Generates a case-sensitive regular expression with all string literals converted to uppercase.
- ABNF_UPPERCASE : Generates a case-sensitive regular expression with all string literals converted to lowercase.
## Legal Stuff
Copyright (c) 2013-2024 Michael R Sweet
This software is provided under the terms of the MIT license, which is provided
in the file "LICENSE.md".