Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/as400jplpc/zig_regex
PCRE2-POSIX REGEX-ZIG
https://github.com/as400jplpc/zig_regex
pcre-regex posix regex-match zig
Last synced: about 2 months ago
JSON representation
PCRE2-POSIX REGEX-ZIG
- Host: GitHub
- URL: https://github.com/as400jplpc/zig_regex
- Owner: AS400JPLPC
- Created: 2023-07-10T09:43:56.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-14T07:08:25.000Z (3 months ago)
- Last Synced: 2024-10-15T02:44:21.134Z (3 months ago)
- Topics: pcre-regex, posix, regex-match, zig
- Language: Zig
- Homepage:
- Size: 5.52 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ZIG_REGEX
PCRE2-POSIX
Using "regex" from the new PCRE2-Posix standard
https://github.com/mnemnion/mvzr new regex form ZIG
example:
Pay attention to the flag that is incumbent on you.
/i ignore case
/g global
/m multiline```
const std = @import("std");// tools regex
const reg = @import("match");const allocatorPrint = std.heap.page_allocator;
pub fn main() !void {
const stdin = std.io.getStdIn().reader();
var buf : [3]u8 = undefined;
buf = [_]u8{0} ** 3;std.debug.print("Macth abc {} \r\n",.{reg.isMatch("p1","^[A-Z]{1,1}[a-zA-Z0-9]{0,}$/g")}) ;
std.debug.print("Macth abc {} \r\n",.{reg.isMatch("p1","^[a-zA-Z]{1,1}[a-zA-Z0-9]{0,}$")}) ;
std.debug.print("MVZR pè1éàaÇ test {} \r\n",.{
isMatch("pè1CéàaÇ","^[a-zA-Z]{1}(\\é|\\à|\\è|\\Ç|[a-zA-Z0-9]){1,7}$")}) ;std.debug.print("Macth digit {} \r\n",.{reg.isMatch(
"423",
"^[1-9]{1,1}?[0-9]{0,}$")}) ;std.debug.print("Macth tel fr{} \r\n",.{reg.isMatch(
"+(33)6.12.34.56.78",
"^[+]{1,1}[(]{0,1}[0-9]{1,3}[)]([0-9]{1,3}){1,1}([-. ]?[0-9]{2,3}){2,4}$")}) ;std.debug.print("Macth tel us{} \r\n",.{reg.isMatch(
"+(001)456.123.789",
"^[+]{1,1}[(]([0-9]{3,3})[)]([-. ]?[0-9]{3}){2,4}$")}) ;
std.debug.print("Macth date fr{} \r\n",.{reg.isMatch(
"12/10/1951",
"^(0[1-9]|[12][0-9]|3[01])[\\/](0[1-9]|1[012])[\\/][0-9]{4,4}$")});std.debug.print("Macth date us{} \r\n",.{reg.isMatch(
"10/12/1951",
"^(0[1-9]|1[012])[\\/](0[1-9]|[12][0-9]|3[01])[\\/][0-9]{4,4}$")});std.debug.print("Macth date iso{} \r\n",.{reg.isMatch(
"2003-02-25",
"^([0-9]{4,4})[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$")});// https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression
// chapitre RFC 6532 updates 5322 to allow and include full, clean UTF-8.std.debug.print("Macth Mail{} \r\n",.{reg.isMatch(
"[email protected]",
"^([-!#-\'*+\\/-9=?A-Z^-~]{1,64}(\\.[-!#-\'*+\\/-9=?A-Z^-~]{1,64})*|\"([]!#-[^-~ \t]|(\\[\t -~]))+\")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+$")});//oreilly
std.debug.print("Macth Mail{} \r\n",.{reg.isMatch(
"[email protected]",
"^[A-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[A-Z0-9.-]+$")});var width :usize = 5;
// unsigned digit
std.debug.print("Macth digit unsigned{} \r\n",.{reg.isMatch(
"123",
std.fmt.allocPrint(allocatorPrint,"^[0-9]{s}{d}{s}$",.{"{1,",width,"}"},) catch unreachable)});// unsigned digit
std.debug.print("Macth digit {} \r\n",.{reg.isMatch(
"+12345",
std.fmt.allocPrint(allocatorPrint,"^[+-][0-9]{s}{d}{s}$",.{"{1,",width,"}"},) catch unreachable)});
// decimal unsigned scal = 0
std.debug.print("Macth decimal unsigned scal = 0 {} \r\n",.{reg.isMatch(
"12345",
std.fmt.allocPrint(allocatorPrint,"^[0-9]{s}1,{d}{s}$",.{"{",width,"}"},) catch unreachable)});var scal :usize = 2;
// decimal unsigned scal > 0
std.debug.print("Macth decimal unsigned scal > 0 {} \r\n",.{reg.isMatch(
"12345.02",
std.fmt.allocPrint(allocatorPrint,
"^[0-9]{s}1,{d}{s}[.][0-9]{s}{d}{s}$",.{"{",width,"}","{",scal,"}"}
) catch unreachable)});_= try stdin.readUntilDelimiterOrEof(buf[0..], '\n');
// decimal signed scal = 0
std.debug.print("Macth decimal signed scal = 0 {} \r\n",.{reg.isMatch(
"+12345",
std.fmt.allocPrint(allocatorPrint,"^[+-][0-9]{s}1,{d}{s}$",.{"{",width,"}"},) catch unreachable)});// decimal unsigned scal > 0
std.debug.print("Macth decimal signed scal > 0 {} \r\n",.{reg.isMatch(
"+12345.02",
std.fmt.allocPrint(allocatorPrint,
"^[+-][0-9]{s}1,{d}{s}[.][0-9]{s}{d}{s}$",.{"{",width,"}","{",scal,"}"}
) catch unreachable)});var i: usize = 0 ;
while(i < 5000) : ( i += 1 ) {
_=reg.isMatch(
"1951-10-12",
"^([0-9]{4,4})[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])$");
}buf = [_]u8{0} ** 3;
_= try stdin.readUntilDelimiterOrEof(buf[0..], '\n');
}```
* •upgrade 2024-03-23.
* •upgrade 2024-06-29.
← zig version 0.13.0* •upgrade 2024-07-01.
← Test Fluent and PCRE "C" Zregex
* •upgrade 2024-07-22.
← Test MVZR and PCRE "C" Zregex
* •upgrade 2024-08-12.
← zig version 0.13.0/ 0.14* •upgrade 2024-09-01.
← zig version 0.14