Created
March 6, 2013 19:50
-
-
Save alganet/5102452 to your computer and use it in GitHub Desktop.
Greppy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Matches a single char. Equivalent to: /./ | |
Pattern::char()->test('a'); //true | |
Pattern::char()->replace('a', 'b'); //b | |
Pattern::char()->match('a'); //array('a') (captures groups) | |
// Possible "steps": | |
Pattern::char(); | |
Pattern::char('A-Z'); // Range [A-Z] | |
Pattern::char('a', 'b', 'c-d'); // List [abc-d] | |
Pattern::none('a'); // [^a] (same as char but negating) | |
Pattern::grouping( | |
Pattern::char('a'), | |
Pattern::char('b') | |
); // ([a]|[b]) | |
Pattern::hidden( | |
Pattern::char('a'), | |
Pattern::char('b') | |
); // (?:[a]|[b]) | |
Pattern::grouping('a', 'b'); // Same as above | |
Pattern::digit()->count('*'); // \d* | |
Pattern::digit()->count(1); // \d{1} | |
Pattern::digit()->count(2,3); // \d{2,3} | |
Pattern::digit()->max(3); // \d{,3} | |
Pattern::digit()->min(2); // \d{2,} | |
Pattern::beginLine()->char()->count('*')->endLine(); // ^.*$ | |
Pattern::line(Pattern::char()->count('*')); // ^.*$ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not sure if I would expose an API for the
preg_
related functions.Maybe using it the usual way looks more verbose:
About this:
I think a method for the actual intent is more verbose:
This:
I prefer the first way, it's definitely more fluent.