You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -103,7 +104,7 @@ EloquentRegex::start("#hello #world This is a #test")->hash()->text()->get();
103
104
-**Ready-to-Use Patterns**: Common patterns like emails, URLs, IP addresses and etc. are pre-defined and ready to go. Just a few keystrokes and you're validating.
104
105
-**Custom Patterns Made Easy**: Build your own regex patterns with an easy-to-use, fluent interface. Say hello to readable regex!
105
106
-**Useful actions**: You can perform various actions with your pattern, from simply validating and getting the matches to complex actions like `search` or `replace`.
106
-
-**Options and Filters**: Tailor your regex operations with options and filters for precision matching.
107
+
-**Options and Filters**: Tailor your regex operations with options and filters like `onlyMasterCard`, `maxSpaces`, `validIPv6` and etc. for more precision.
107
108
-**Laravel Integration**: Seamlessly integrates with your Laravel projects, leveraging Laravel's elegant syntax and features like collection.
108
109
109
110
_For more details about package and it's inner workings check out [STRUCTURE.md](https://github.com/MaestroError/eloquent-regex/blob/update-documentation-and-add-advanced-usage-section/STRUCTURE.md) file._
@@ -122,7 +123,7 @@ Need to get started quickly? Read the [quick start guide](https://medium.com/@re
122
123
123
124
# Basic Usage
124
125
125
-
EloquentRegex simplifies regular expressions in Laravel, making it easy to validate data, search text, and extract information. This section introduces the basic usage of EloquentRegex, including leveraging **ready-to-use patterns** and creating **custom patterns**.
126
+
EloquentRegex simplifies regular expressions in Laravel, making it easy to validate data, search text, and extract information. This section introduces the basic usage of EloquentRegex, including leveraging [ready-to-use](#ready-to-use-patterns) patterns and creating [custom](#custom-patterns%EF%B8%8F) patterns.
126
127
127
128
First of all, you need to include EloquentRegex class.
128
129
@@ -138,11 +139,11 @@ use Maestroerror\EloquentRegex\Facades\EloquentRegex;
138
139
139
140
## Actions
140
141
141
-
Actions are end methods created to finilize your pattern and take some action with it. So they are the main features of the package as well. Let's discuss them one by one and check the examples for [custom](#custom-patterns%EF%B8%8F) and [ready-to-use](#ready-to-use-patterns) patterns.
142
+
Actions are end methods created to finilize your pattern and take some action with it. So they are the main features of the package as well. Let's discuss them one by one and check the examples.
142
143
143
144
### Get
144
145
145
-
Returns all matches as array/collection.
146
+
Returns all matches as array/collection. Returns `null` if no matches found.
146
147
147
148
_Example with ready-to-use pattern_
148
149
@@ -227,7 +228,7 @@ EloquentRegex::start("#hello #world This is a #test")
227
228
228
229
### Replace
229
230
230
-
Counts amount of matches and returns as int. Returns `0` if no matches found.
231
+
Replaces found matches in given source string using provided **callback**.
Search method searches for **keyword** or **pattern** in multiline text and returns lines where subject is found. It is especially useful with processing of large files like logs or JSON.
274
+
Search method searches for **keyword** or **pattern**(including ready-to-use patterns too) in multiline text and returns lines where subject is found. It is especially useful with processing of large files like logs or JSON.
274
275
275
276
_Example with keyword search_
276
277
@@ -326,9 +327,30 @@ EloquentRegex::source(
326
327
*/
327
328
```
328
329
330
+
#### Search benchmark
331
+
332
+
_Interesting fact: As shorter keyword is, the faster the search methods work_
333
+
334
+
Check benchmark of `search` for keyword "green" in large JSON file, where each line was JSON object from DB:
SearchReverse method searches for **keyword** or **pattern** in multiline text and returns every line which doesn't contains subject. It is especially useful while processing of large files like logs or JSON.
353
+
SearchReverse method searches for **keyword** or **pattern** in multiline text and returns every line which **doesn't contain** subject. It is especially useful while processing large text files like logs or JSON.
It is same as capturing group but named and is used to group part of a pattern together and capture the matching text for later use with it's name. Note that it returs array/collection with different structure while using with get:
1124
+
1125
+
```php
1126
+
// Matching a date format with capturing the parts as separated groups
1127
+
EloquentRegex::start("RI-2142, PO-2555")
1128
+
->namedGroup(function ($pattern) {
1129
+
return $pattern->textUppercase(2);
1130
+
}, "project", 1)
1131
+
->dash()
1132
+
->namedGroup(function ($pattern) {
1133
+
return $pattern->digitsRange(2, 4);
1134
+
}, "issue", 1)
1135
+
->get();
1136
+
1137
+
/* Returns:
1138
+
[
1139
+
"result" => "RI-2142",
1140
+
"groups" => [
1141
+
"project" => "RI",
1142
+
"issue" => "2142",
1143
+
]
1144
+
],
1145
+
[
1146
+
"result" => "PO-2555",
1147
+
"groups" => [
1148
+
"project" => "PO",
1149
+
"issue" => "2555",
1150
+
]
1151
+
]
1152
+
*/
1153
+
```
1154
+
1099
1155
### Non-Capturing Groups
1100
1156
1101
1157
Non-capturing groups organize patterns logically without capturing separately the matched text.
0 commit comments