Skip to content

Commit ac3c26c

Browse files
committed
first part of docs ready
1 parent 64c8a96 commit ac3c26c

File tree

1 file changed

+122
-5
lines changed

1 file changed

+122
-5
lines changed

README.md

Lines changed: 122 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,122 @@
22

33
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.
44

5-
#### Adding new options
5+
# Overview
66

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? 😄🚀
88

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!
1010

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**!
1212

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:
14+
15+
```php
16+
$isValid = EloquentRegex::source('[email protected]')->email()->check();
17+
```
18+
19+
## Key Features
20+
21+
- **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
84+
EloquentRegex::source($yourString)->url()->check();
85+
86+
// checkString() will return true if $yourString contains any matches of the pattern
87+
// In this case, if $yourString contains minimum 1 URL, false otherwise
88+
EloquentRegex::source($yourString)->url()->checkString();
89+
90+
// count() will return count of matches, in this case, amount of URLs in $yourString
91+
EloquentRegex::source($yourString)->url()->count();
92+
93+
// toRegex() will return string - raw regex pattern (without options applied)
94+
EloquentRegex::source($yourString)->url()->toRegex();
95+
```
96+
97+
## Ready-to-Use Patterns
98+
99+
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 `"$, ₾"`
119+
- `filePath(int $isDirectory, bool $isFile, bool $fileExists,string $pathType)` - $pathType allowed values: `absolute` & `relative`
120+
- `filePathWin(int $isDirectory, bool $isFile, bool $fileExists)`
14121

15122
#### Quantifiers
16123

@@ -55,6 +162,8 @@ Examples: `->exact("hello world", false, "1+")`
55162

56163
- Make Tests for quantifiers (add grouping) ✔️
57164
- Make quantifiers available for special chars ✔️
165+
- Return collection on get method if laravel is available.
166+
- Create quick start guide and add in Docs.
58167

59168
##### Coming next
60169

@@ -65,3 +174,11 @@ Examples: `->exact("hello world", false, "1+")`
65174
- Make patterns controllable from config or provider (?)
66175
- I should be able to make new pattern using BuilderPattern
67176
- I should be able to make add custom pattern to the existing one using BuilderPattern
177+
178+
```
179+
180+
```
181+
182+
```
183+
184+
```

0 commit comments

Comments
 (0)