1- ## FLUX (Fluent Regular Expressions)
1+ ## FLUX (Fluent Regular Expressions) 0.3.0
22* by* [ Selvin Ortiz] ( http://twitter.com/selvinortiz )
33
44### Description
55Fluent Regular Expressions _ for_ PHP
66
77----
88
9- ### Changelog
9+ ### @Changelog
10+
11+ ----
12+ #### 0.3.0
13+ - Improves documentation with ` phone/date ` examples
14+ - Adds the ` letters() ` method
15+ - Renames the ` numbers() ` method to ` digits() `
16+ - Adds support for quantifiers for ` digits() `
17+ - Adds ` ignoreCase() ` and promotes it above ` inAnyCase() `
18+ - Improves the documented API
19+
20+ * _ Thought hard about changing the name to `FluentX' any thoughts?_
1021
1122----
1223#### 0.2.0
@@ -20,13 +31,25 @@ Initial preview release
2031
2132----
2233
23- ### Example
24- ----
34+ ### @Todo
35+ - Add source code comments
36+ - Add support for quantifiers
37+ - Add language methods for more advanced use cases
38+ - Add support for array/array replacements
39+ - Add reference to repos that have port ` FLUX `
40+ - Add license notes
41+ - Add contributing notes
42+ - Add credits
43+
44+ ### @Examples
2545
2646``` php
27- $flux = new Flux();
28- $subject = 'http://selvinortiz.com';
47+ /**
48+ * Build a URL pattern then test w/ match() and do a replace()
49+ */
2950
51+ $url = 'http://www.selvinortiz.com';
52+ $flux = new Flux();
3053$flux
3154 ->startOfLine()
3255 ->find('http')
@@ -38,14 +61,51 @@ $flux
3861 ->inAnyCase()
3962 ->endOfLine();
4063
41- // Echoing the instance will yield the compiled pattern (__toString)
42- echo $flux; // /^(http)(s)?(\:\/\/)(www\.)?([^\.]*)(.in|.co|.com)$/i
64+ // Pattern /^(http)(s)?(\:\/\/)(www\.)?([^\.]*)(.in|.co|.com)$/i
65+ echo $flux->match( $url ); // true
66+ echo $flux->replace( 'https://$5$6', $url ); // https://selvinortiz.com
67+
68+ /**
69+ * Build a US Date pattern then test w/ match() and do a replace()
70+ */
4371
44- // Match against the subject string
45- echo $flux->match( $subject ); // TRUE
72+ $date = 'Monday, Jul 22, 2013';
73+ $flux = new Flux();
74+ $flux
75+ ->startOfLine()
76+ ->word()
77+ ->then(', ')
78+ ->letters(3)
79+ ->then(' ')
80+ ->digits(1, 2)
81+ ->then(', ')
82+ ->digits(4)
83+ ->endOfLine();
84+
85+ // Pattern /^(\()(\d{3})(\))( )?(\d{3})([ \-])(\d{4})$/
86+ echo $flux->match( $date ) ? 'matched' : 'unmatched'; // matched
87+ echo $flux->replace( '$3/$5/$7', $date ); // 612.424.0013
88+
89+ /**
90+ * Build a US Phone Number pattern then test w/ match() and do a replace()
91+ */
92+
93+ $phone = '(612) 424-0013';
94+ $flux = new Flux();
95+ $flux
96+ ->startOfLine()
97+ ->find('(')
98+ ->digits(3)
99+ ->then(')')
100+ ->maybe(' ')
101+ ->digits(3)
102+ ->anyOf(' -')
103+ ->digits(4)
104+ ->endOfLine();
46105
47- // Replace the subject with matched segment $5 and $6
48- echo $flux->replace( '$5$6', $subject ); // selvinortiz.com
106+ // Pattern /^(\()(\d{3})(\))( )?(\d{3})([ \-])(\d{4})$/
107+ echo $flux->match( $phone ) ? 'matched' : 'unmatched'; // matched
108+ echo $flux->replace( '$2.$5.$7', $phone ); // 612.424.0013
49109```
50110
51111### FLUX API
@@ -58,23 +118,54 @@ Adds a beginning of line `^` modifier
58118Adds an end of line ` $ ` modifier
59119
60120#### ` find( $val ) `
61- The first ` segment ` in the pattern, also an alias to ` then( $val ) `
62-
63121#### ` then( $val ) `
64- Allows you to augment the pattern with a required segment and like ` find() ` , it escapes regular expression chars
122+ Allow you to augment the pattern with a required ` segment ` and it escapes regular expression chars
65123
66124#### ` maybe( $val ) `
67- Allows you to augment the pattern with an optional segment
125+ Allows you to augment the pattern with an optional ` segment `
126+
127+ #### ` any( $val ) `
128+ #### ` anyOf( $val ) `
129+ Creates a character class behind the scenes so that you can optionally match different chars
130+
131+ #### ` anything() `
132+ Adds a * wild card* ` (.*) ` ` segment ` to the pattern but it does not make ` dotAll() ` explicit
133+
134+ #### ` anythingBut( $val ) `
135+ Will match anything but the chars in ` $val ` which is opposite of ` any() ` and ` anyOf `
136+
137+ #### ` word() `
138+ Adds ` (\w+) ` to the pattern which will match a single word
139+
140+ #### ` letters( $min=null, $max=null ) `
141+ Only matches chars in the alphabet and uses ` $min ` and ` $max ` to create a quantifier
142+
143+ #### `digits( $mix=null, $max=null )
144+ Only matches digits and uses ` $min ` and ` $max ` to create a quantifier like ` word() `
145+
146+ #### ` range( $from, $to [, $from, $to ...]) `
147+ Allows you to create a ` range ` character class like ` a-z0-9 ` by calling ` range('a', 'z', 0, 9) `
148+
149+ #### ` orTry() `
150+ This is experimental and I don't have the implementation I feel comfortable with...
151+
152+ #### ` ignoreCase() `
153+ #### ` inAnyCase() `
154+ Adds the ` i ` modifier to the pattern which will allow you to match in a case insensitive manner
155+
156+ #### ` dotAll() `
157+ Adds the ` s ` modifier to the pattern which will allow you to match a ` new line ` when using ` anything() `
68158
69- #### ` any ()`
70- Adds a * wild card * ` (.*) ` segment to the pattern but it does not make ` dotAll() ` explicit
159+ #### ` multiline ()`
160+ Adds the ` m ` modifier to the pattern which will allow you to search across multiple lines
71161
72- #### ` anyOf ()`
73- Alias to ` any ()`
162+ #### ` searchOneLine ()`
163+ Removes the modifier added by ` multiline ()` if it was previously called
74164
75165#### ` match( $subject ) `
166+ Simply takes your ` $subject ` in, compares it against the pattern, and returns whether a it matched or not
76167
77168#### ` replace( $replacement, $subject ) `
169+ You can replace matched ` segments ` by using the ` $x ` format where ` x ` is the ` (int) ` position of the matched ` segment `
78170
79- #### ` (...) `
80- There are plenty of other methods to document but I'll get to the rest shortly.
171+ ### (...)
0 commit comments