Skip to content

Commit 1d715ec

Browse files
committed
Replace, search, searchReverse & swap methods, support for named groups + fixes
1 parent 74df029 commit 1d715ec

File tree

8 files changed

+624
-23
lines changed

8 files changed

+624
-23
lines changed

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Like what we're doing? Show your support with a quick star, please! ⭐
1010

1111
Want the same power directly in the browser? Check out the JS version: [SimplifiedRegex](https://github.com/MaestroError/simplified-regex) 🚀
1212

13-
Feeling overwhelmed by the documentation? With a ChatGPT Plus subscription, you can streamline your experience by utilizing the [EloquentRegex Assistant](https://chat.openai.com/g/g-CtG1m2bI7-eloquentregex-assistant) GPT 🤖
13+
Feeling overwhelmed by the documentation? You can streamline your experience by utilizing the [EloquentRegex Assistant](https://chat.openai.com/g/g-CtG1m2bI7-eloquentregex-assistant) GPT 🤖
1414

1515
### Table of Contents
1616

@@ -47,11 +47,11 @@ Feeling overwhelmed by the documentation? With a ChatGPT Plus subscription, you
4747
- 💠 [Non-Capturing Groups](#non-capturing-groups)
4848
- 💠 [Groups with quantifier](#groups-with-quantifier)
4949
-[Conditional matching](#conditional-matching)
50-
- ⚖️[Pattern alternation (orPattern)](#pattern-alternation-orpattern)
50+
- ⚖️[Pattern alternation (orPattern)](#pattern-alternation-orpattern%EF%B8%8F)
5151
- 🧩[Raw Methods](#raw-methods)
5252
- 🐌[The Lazy Quantifier Method](#the-lazy-quantifier-method)
5353
- **[Testing and Debugging Your Regex Patterns](#testing-and-debugging-your-regex-patterns)**
54-
- **[Contributing to EloquentRegex](#contributing-to-eloquenttegex)**
54+
- **[Contributing to EloquentRegex](#contributing-to-eloquentregex)**
5555
- **[Support](#support)**
5656
- **[Credits](#credits)**
5757
- **[Frequently Asked Questions (FAQ)](#frequently-asked-questions-faq)**
@@ -320,10 +320,10 @@ _Note: You can use `EloquentRegex::builder()->pattern()` if you need just build
320320

321321
Custom pattern builder supports a wide range of character classes and all special chars. Also, `literal` or `exact` method could be used to match exact string you need, or `char` method could be used to match exact character. The full list of pattern builder methods is comming soon. Before that, you can check this files out:
322322

323-
- [Character Classes](https://github.com/MaestroError/eloquent-regex/blob/documentation-and-examples/src/Traits/BuilderPatternTraits/CharacterClassesTrait.php)
324-
- [Special characters](https://github.com/MaestroError/eloquent-regex/blob/documentation-and-examples/src/Traits/BuilderPatternTraits/SpecificCharsTrait.php)
325-
- [Groups](https://github.com/MaestroError/eloquent-regex/blob/documentation-and-examples/src/Traits/BuilderPatternTraits/GroupsTrait.php)
326-
- [Anchors](https://github.com/MaestroError/eloquent-regex/blob/documentation-and-examples/src/Traits/BuilderPatternTraits/AnchorsTrait.php)
323+
- [Character Classes](https://github.com/MaestroError/eloquent-regex/blob/maestro/src/Traits/BuilderPatternTraits/CharacterClassesTrait.php)
324+
- [Special characters](https://github.com/MaestroError/eloquent-regex/blob/maestro/src/Traits/BuilderPatternTraits/SpecificCharsTrait.php)
325+
- [Groups](https://github.com/MaestroError/eloquent-regex/blob/maestro/src/Traits/BuilderPatternTraits/GroupsTrait.php)
326+
- [Anchors](https://github.com/MaestroError/eloquent-regex/blob/maestro/src/Traits/BuilderPatternTraits/AnchorsTrait.php)
327327

328328
## Applying Quantifiers#️⃣
329329

@@ -860,7 +860,7 @@ Matches digits only if they are preceded by a 'P'
860860
```php
861861
// Expected to be true as '3' is preceded by 'P'
862862
EloquentRegex::start('P3')
863-
->negativeLookBehind(function($pattern) {
863+
->lookBehind(function($pattern) {
864864
$pattern->character('P');
865865
})->digits()->check();
866866
// While using "get()" method, 'P' doesn't appear in matches
@@ -1180,15 +1180,32 @@ To stay updated, follow the GitHub repository for the latest changes, releases,
11801180

11811181
##### To Do
11821182

1183+
- Fix traits URLs in docs ✅
1184+
- Add replace method ✅
1185+
- Add reverse method (to get everything except matched pattern) - try negative lookBehind or Lookahead with big texts ✅
1186+
- Search and SearchReverse with keyword or pattern, check the searchTest\search.php file
1187+
- Implement usage of named groups: `/(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})/`
1188+
- Make available to do thing like this: “/container-[MATERIAL_NAME]-[NUMBER]” → “/konfigurator/materialien?material=[MATERIAL_NAME]
11831189
- Add options for new patterns:
11841190
- Add `contains` and `notContains` options
11851191
- usernameLength: Set minimum and maximum length for the username part of the email.
11861192
- dateFormat, timeFormat: Specify the format of date and time (e.g., MM-DD-YYYY, HH:MM).
1187-
- Implement usage of named groups: `/(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})/`
11881193
- Create some tool for debuging the Options
11891194

11901195
- Write documentation:
1191-
- Create quick start guide and add in Docs. +
1196+
1197+
- Create quick start guide and add in Docs. ✅
1198+
- Add in Basic Usage topic the "Features" docs with both pattern examples
1199+
1200+
- get
1201+
- check
1202+
- checkString
1203+
- count
1204+
- toRegex
1205+
- replace
1206+
- search
1207+
- searchReverse
1208+
11921209
- Add builderPattern methods list MD file and link from the Docs.
11931210
- Add options debuging section in docs
11941211

@@ -1201,3 +1218,4 @@ To stay updated, follow the GitHub repository for the latest changes, releases,
12011218
- Implement first() method using preg_match instead of preg_match_all
12021219
- I should be able to make new pattern using BuilderPattern
12031220
- I should be able to add custom pattern to the existing one using BuilderPattern
1221+
- I should be able to add custom option using BuilderPattern, raw regex or regular PHP functions

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
"pestphp/pest-plugin": true
2424
}
2525
},
26+
"scripts": {
27+
"test": "./vendor/bin/pest"
28+
},
2629
"extra": {
2730
"laravel": {
2831
"providers": [
@@ -33,4 +36,4 @@
3336
}
3437
}
3538
}
36-
}
39+
}

namedGroupsTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
require __DIR__ . "/vendor/autoload.php";
4+
5+
use Maestroerror\EloquentRegex\Builder;
6+
7+
8+
$builder = new Builder("RI-2142, RI-1234, KI-8996, PO-2555");
9+
$result = $builder->pattern(function ($builder) {
10+
return $builder
11+
->namedGroup(function ($pattern) {
12+
return $pattern->textUppercase(2);
13+
}, "project", 1)
14+
->dash()
15+
->namedGroup(function ($pattern) {
16+
return $pattern->digitsRange(2, 4);
17+
}, "issue", 1);
18+
});
19+
20+
$results = $result->get();
21+
22+
foreach ($results as $item) {
23+
$id = $item["result"];
24+
$projectPart = $item["groups"]["project"];
25+
$issueNumber = $item["groups"]["issue"];
26+
echo "ID: $id; Project: $projectPart; Issue: $issueNumber\n";
27+
}

0 commit comments

Comments
 (0)