Skip to content

Commit db17ce8

Browse files
committed
Updated docs
1 parent 34961af commit db17ce8

File tree

2 files changed

+734
-12
lines changed

2 files changed

+734
-12
lines changed

README.md

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ Feeling overwhelmed by the documentation? You can streamline your experience by
2424
- [CheckString](#checkstring)
2525
- [Count](#count)
2626
- [Replace](#replace)
27-
- [ToRegex](#get-regex)
27+
- [ToRegex](#toregex)
2828
- [Search](#search)
29+
- [Search benchmark](#search-benchmark)
2930
- [SearchReverse](#searchreverse)
30-
- [Swap](#Swap)
31+
- [Swap](#swap)
3132
- 📑[Ready-to-Use Patterns](#ready-to-use-patterns)
32-
- 🛠️[Custom Patterns](#custom-patterns)
33+
- 🛠️[Custom Patterns](#custom-patterns%EF%B8%8F)
3334
- 💠 [Creating a Custom Pattern](#creating-a-custom-pattern)
34-
- #️⃣[Applying Quantifiers](#applying-quantifiers)
35+
- #️⃣[Applying Quantifiers](#applying-quantifiers%EF%B8%8F⃣)
3536
- 💠 [Optional Elements](#optional-elements)
3637
- 💠 [Specifying a Range](#specifying-a-range)
3738
- 💠 [One or More](#one-or-more)
@@ -51,7 +52,7 @@ Feeling overwhelmed by the documentation? You can streamline your experience by
5152
- 💠 [Single-Line Mode](#single-line-mode)
5253
- 💠 [Unicode Character Matching](#unicode-character-matching)
5354
- **[Advanced builderPattern methods](#advanced-builderpattern-methods)**
54-
- 🗃️[Character Sets](#character-sets)
55+
- 🗃️[Character Sets](#character-sets%EF%B8%8F)
5556
- 📦[Groups](#groups)
5657
- 💠 [Capturing Groups](#capturing-groups)
5758
- 💠 [Non-Capturing Groups](#non-capturing-groups)
@@ -103,7 +104,7 @@ EloquentRegex::start("#hello #world This is a #test")->hash()->text()->get();
103104
- **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.
104105
- **Custom Patterns Made Easy**: Build your own regex patterns with an easy-to-use, fluent interface. Say hello to readable regex!
105106
- **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.
107108
- **Laravel Integration**: Seamlessly integrates with your Laravel projects, leveraging Laravel's elegant syntax and features like collection.
108109

109110
_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
122123

123124
# Basic Usage
124125

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.
126127

127128
First of all, you need to include EloquentRegex class.
128129

@@ -138,11 +139,11 @@ use Maestroerror\EloquentRegex\Facades\EloquentRegex;
138139

139140
## Actions
140141

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.
142143

143144
### Get
144145

145-
Returns all matches as array/collection.
146+
Returns all matches as array/collection. Returns `null` if no matches found.
146147

147148
_Example with ready-to-use pattern_
148149

@@ -227,7 +228,7 @@ EloquentRegex::start("#hello #world This is a #test")
227228

228229
### Replace
229230

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**.
231232

232233
_Example with ready-to-use pattern_
233234

@@ -270,7 +271,7 @@ EloquentRegex::builder()->start()
270271

271272
### Search
272273

273-
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.
274275

275276
_Example with keyword search_
276277

@@ -326,9 +327,30 @@ EloquentRegex::source(
326327
*/
327328
```
328329

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:
335+
336+
```php
337+
/*
338+
===========================================================
339+
| ROWS | Find time (count) | File size | Find + decoded |
340+
===========================================================
341+
| 1000 | 7.6 ms (890) | 5 Mb | 11.5 ms |
342+
| 2500 | 17.25ms (2186) | 14 Mb | 30 ms |
343+
| 5000 | 34.4 ms (4347) | 29 Mb | 62 ms |
344+
| 10K | 67.4 ms (8669) | 58 Mb | 112 ms |
345+
| 20K | 131 ms (17313) | 116 Mb | 251 ms |
346+
===========================================================
347+
===Keyword:="green"========================================
348+
*/
349+
```
350+
329351
### SearchReverse
330352

331-
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.
332354

333355
_Example with keyword search_
334356

@@ -1096,6 +1118,40 @@ $result = EloquentRegex::start("2024-01-30, 2023-02-20")
10961118
*/
10971119
```
10981120

1121+
### Named Capturing Groups
1122+
1123+
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+
10991155
### Non-Capturing Groups
11001156

11011157
Non-capturing groups organize patterns logically without capturing separately the matched text.

0 commit comments

Comments
 (0)