Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/add-support-for-pregMatch #18

Merged
merged 6 commits into from
Nov 12, 2024
Merged

Conversation

zero-to-prod
Copy link
Owner

Description

pregMatch

Use pregMatch to perform a regular expression match.

class User
{
    use \Zerotoprod\DataModel\DataModel;
    use \Zerotoprod\DataModelHelper\DataModelHelper;

    #[Describe([
        'cast' => [self::class, 'pregMatch'],
        'pattern' => '/s/', // Required
        'match_on' => 0 // Index of the $matches to return
        'flags' => PREG_UNMATCHED_AS_NULL
        'offset' => 0
    ])]
    public string $name;
}

$User = User::from([
    'name' => 'sarah',
]);

echo $User->name; // Outputs: 's'

@zero-to-prod zero-to-prod self-assigned this Nov 12, 2024
@zero-to-prod zero-to-prod added the enhancement New feature or request label Nov 12, 2024
@zero-to-prod zero-to-prod merged commit 1aa3e93 into main Nov 12, 2024
3 checks passed
@zero-to-prod zero-to-prod deleted the feat/add-support-for-pregMatch branch November 12, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant