Easy work with regex groups

2023/07/14
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The Bog Jug library is a helpful tool for developers working with regular expressions in their code. It provides an easy way to convert regex groups into objects, making it simpler to work with the captured data.

To use Bog Jug, simply install it using Composer:

composer require ta-tikoma/bog-jug

Once installed, you can start using it in your code. Here's an example:

// Define class of descriptions
class Description {
    public $name;
    public $age;
}

// Call method of BogJug
$result = \BogJug::convertRegexGroupToObject('/Name: (\w+), Age: (\d+)/', 'Name: John, Age: 25');

// Take result
$description = new Description();
$description->name = $result->name;
$description->age = $result->age;

echo $description->name; // Output: John
echo $description->age; // Output: 25

With Bog Jug, you can easily extract and manipulate data from regex groups in a more organized and efficient way. It's a valuable tool for developers working with regular expressions.