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
Copy file name to clipboardExpand all lines: README.md
+122-5Lines changed: 122 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,122 @@
2
2
3
3
Eloquent Regex brings the simplicity and elegance to regular expressions. Designed for Laravel developers, this package offers a fluent, intuitive interface for building and executing regex patterns in your PHP applications.
4
4
5
-
#### Adding new options
5
+
#Overview
6
6
7
-
All available option classes and option names are hardcoded in `src\OptionsMapper.php`. Refer to it, if you want add new or disable existing one.
7
+
### Dreaming of a world where regex doesn't feel like rocket science? 😄🚀
8
8
9
-
Think about options as an extra assertions you add to the pattern. To keep it simple, all options (so the option methods too) should have only 1 argument.
9
+
Regular expressions (regex) are powerful, no doubt. They're the Swiss Army knife for string manipulation and validation. But let's be honest, they can also be a bit of a headache. The syntax is dense, and a tiny mistake can throw everything off. It's like they're designed to be as intimidating as possible, especially when you're just trying to validate an email address!
10
10
11
-
#### Adding new patterns
11
+
Enter **EloquentRegex**. Our goal is to make working with regex in Laravel not just bearable, but actually enjoyable. Yes, you heard that right—**enjoyable**!
12
12
13
-
All available redy-to-use pattern classes are hardcoded in `src\Builder.php`. Refer to it, if you want add new or disable existing one.
13
+
EloquentRegex is a PHP/Laravel package that offers a fluent, intuitive interface for constructing and executing regular expressions. Whether you need to validate user input, parse text, or extract specific information from strings, EloquentRegex makes it simple and straightforward. For example:
-**Ready-to-Use Patterns**: Common patterns like emails, URLs, and IP addresses are pre-defined and ready to go. Just a few keystrokes and you're validating.
22
+
-**Custom Patterns Made Easy**: Build your own regex patterns with an easy-to-use, fluent interface. Say hello to readable regex!
23
+
-**Options and Filters**: Tailor your regex operations with options and filters for precision matching. It's like having a regex wizard at your fingertips.
24
+
-**Laravel Integration**: Seamlessly integrates with your Laravel projects, leveraging Laravel's elegant syntax and features.
25
+
26
+
## Getting Started
27
+
28
+
Simply install the package via Composer, and you're ready to take the pain out of regex in your PHP/Laravel applications. Follow our quick start guide below to dive in.
29
+
30
+
```bash
31
+
composer require maestroerror/eloquent-regex
32
+
```
33
+
34
+
Later, Here will be added our quick start guide.
35
+
36
+
Remember, regex doesn't have to be a source of frustration. With EloquentRegex, you're on your way to becoming a regex master, all while writing cleaner, more maintainable Laravel code.
37
+
38
+
# Basic Usage
39
+
40
+
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.
41
+
42
+
First of all, you need to include EloquentRegex class.
43
+
44
+
```php
45
+
use Maestroerror\EloquentRegex\EloquentRegex;
46
+
```
47
+
48
+
Recomended for **Laravel:**
49
+
50
+
```php
51
+
use Maestroerror\EloquentRegex\Facades\EloquentRegex;
52
+
```
53
+
54
+
Usage structure is very similar to Laravel's Eloquent ORM, check this out:
55
+
56
+
```
57
+
[Initiator][Pattern][?Optional][Action]
58
+
```
59
+
60
+
Let's break it down:
61
+
62
+
-_Initiator_ sets the target string
63
+
64
+
```php
65
+
EloquentRegex::source($yourString);
66
+
```
67
+
68
+
-_Pattern_ Could be method for one of the ready-to-use patterns or your custom pattern (we will talk about custom pattern later). Let's keep the example simple and add url pattern:
69
+
70
+
```php
71
+
EloquentRegex::source($yourString)->url();
72
+
```
73
+
74
+
_Note: **Optional** methods mostly are the expression flags, we will talk about them in next sections_
75
+
76
+
-_Action_ are execution methods, check the example:
77
+
78
+
```php
79
+
// get() will return array/collection of URLs if any found in $yourString
80
+
EloquentRegex::source($yourString)->url()->get();
81
+
82
+
// check() will return true if $yourString exactly matches the pattern
83
+
// In this case, if $yourString is URL, false otherwise
EloquentRegex comes with a set of predefined patterns for common validation/extraction tasks. These patterns are designed to be straightforward and easy to use, requiring minimal effort to implement.
100
+
101
+
We have different ways to apply options, but the most common and easy way is to pass them as arguments. Note that all arguments are optional.
102
+
103
+
Here you can check all available methods of ready-to-use patterns and their arguments:
104
+
105
+
-`textOrNumbers(int $minLength, int $maxLength, int $minUppercase, int $minLowercase, int $minNumbers, int $maxNumbers)`
106
+
-`email(int $maxLength, array|string $onlyDomains, array|string $onlyExtensions)` - $onlyDomains & $onlyExtensions array or string separated by comma `"example.org,example.com"`
107
+
-`url(array|string $onlyProtocol)`
108
+
-`domainName(int $maxLength, array|string $onlyDomains, array|string $onlyExtensions)` - $onlyDomains & $onlyExtensions array or string separated by comma `"org,com"`
109
+
-`date()`
110
+
-`time()`
111
+
-`ipAddress()`
112
+
-`ipv6Address()`
113
+
-`creditCardNumber(string $cardTypes)` - $cardTypes string separated by comma `"visa, amex"`
114
+
-`phone(string $countryCode)` - $countryCode should passed without "+" sign: `phone("1")`, `phone("995")`
115
+
-`username(int $maxLength)`
116
+
-`password(int $minLength, int $minUppercase, int $minNumbers, int $minSpecialChars)`
117
+
-`htmlTag(array|string $restrictTags, array|string $onlyTags)` - $restrictTags & $onlyTags array or string separated by comma `"script, style"`. It isn't recomended to use both option in simultaneously
118
+
-`currency(int $minDigits, int $maxDigits, array|string $specificCurrencies)`- $specificCurrencies array of currency symbols or string separated by comma `"$, ₾"`
0 commit comments