Skip to content

Commit

Permalink
regex package
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 7, 2024
1 parent 2263353 commit 2b704b6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion library/attribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MyAction {

## Regex

The `Regex` attribute enables to define [Regex](regex.md) for parameters of type `string`.
The `Regex` attribute enables to define [Regex](../packages/regex.md) for parameters of type `string`.

```php
use Chevere\Attributes\Regex;
Expand Down
1 change: 1 addition & 0 deletions packages/naming.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
'workflow.md' => 'Workflow',
'xrdebug.md' => 'xrDebug',
'danky.md' => 'Danky',
'regex.md' => 'Regex',
'http.md' => 'Http',
];
42 changes: 26 additions & 16 deletions library/regex.md → packages/regex.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
# Regex

Namespace `Chevere\Regex`
![Regex](../src/packages/regex/regex-logo.svg)

The Regex component is in charge of providing tooling for [regular expression](https://en.wikipedia.org/wiki/Regular_expression) (regex) patterns.
## Summary

Regex enables to create and handle a validated [regular expression](https://en.wikipedia.org/wiki/Regular_expression).

## Installing

Regex is available through [Packagist](https://packagist.org/packages/chevere/regex) and the repository source is at [chevere/regex](https://github.com/chevere/regex).

```sh
composer require chevere/regex
```

## Creating Regex

Create a Regex by passing the pattern.
Create a Regex by passing the regular expression pattern.

```php
use Chevere\Regex\Regex;

$regex = new Regex('/^Hello World!$/');
```

## Regex pattern
## Reading pattern

### As-is (constructor)
### As-is

The `__toString` method is used to access the pattern passed on instance creation.

Expand All @@ -27,19 +37,19 @@ $string = $regex->__toString();

### Without delimiters

The `toNoDelimiters` method is used to access to the regex pattern without delimiters.
The `noDelimiters` method is used to access to the regex pattern without delimiters.

```php
$string = $regex->toNoDelimiters();
$string = $regex->noDelimiters();
// ^Hello World!$
```

### Without delimiters and anchors

The `toNoDelimitersNoAnchors` method is used to access to the regex pattern without delimiters and anchors.
The `noDelimitersNoAnchors` method is used to access to the regex pattern without delimiters and anchors.

```php
$string = $regex->toNoDelimitersNoAnchors();
$string = $regex->noDelimitersNoAnchors();
// Hello World!
```

Expand All @@ -52,21 +62,21 @@ $array = $regex->match('Hello World!');
// [Hello World!]
```

## Assert Match
## Match All

The `assertMatch` method asserts that the string matches. It throws `Exceptions\NoMatchException` when failing to assert.
The `matchAll` method provides [preg_match_all](https://www.php.net/preg-match-all).

```php
$regex->assertMatch('Hello World!');
$regex->matchAll();
// [Hello World!]
```

## Match All
## Assert Match

The `matchAll` method provides [preg_match_all](https://www.php.net/preg-match-all).
The `assertMatch` method asserts that the string matches. It throws `Exceptions\NoMatchException` when failing to assert.

```php
$regex->matchAll();
// [Hello World!]
$regex->assertMatch('Hello World!');
```

## Assert Match All
Expand Down
14 changes: 14 additions & 0 deletions src/packages/regex/regex-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2b704b6

Please sign in to comment.