Skip to content

Releases: t-regx/T-Regx

0.9.5 - Alternation in prepared patterns!

Choose a tag to compare

@danon danon released this 12 Jun 16:41

😎 T-Regx The Dinosaur is really proud to announce its second beta version! Despite the beta suffix, it's 100% suitable for production use. It doesn't have any known bugs - check out the issues. There is a few breaking changes (since that's a 0.* version), but there are also improvements and new feautres.

The detailed list of changes is in ChangeLog.md.

Here's a summary:

  • Breaking changes

    • Removed iterate() method, which was only used as a substitute for forEach(), pre PHP 7.0, when
      keywords couldn't be used as method names.
    • Renamed pattern()->match()->forFirst() to findFirst() #70
  • Features

    • Added match()->group()->findFirst() #22 #70
    • Added alternating groups in prepared patterns 🔥
      • Pattern::bind(), Pattern::inject() and Pattern::prepare() can now accept string[], which will be treated as a regex alternation group!
        Pattern::bind('Choice: @values', [
            'values' => ['apple?', '[orange]', 'pear']
        ]);
        is similar to
        Pattern::of('Choice: (apple\?|\[orange\]|pear)')
        The alternation is also optimized for i and u flags, for example it will remove case-insensitive duplicates (like foo and FOO when i flag is used).

That's it for this release, stay tuned!

0.9.4 - Exception changes and groupBy!

Choose a tag to compare

@danon danon released this 12 Jun 16:41

What's new, new, new?

This release brings updates in exceptions (namespaces, new detailed exceptions) and a groupBy() method.

Exceptions

In previous realase we renamed SafeRegexException to PregException. In this, we're renaming CleanRegexException to PatternException. So now, those two general exceptions sync nicely with their base methods:

try {
  return preg::match('/Foo/', $subject);
} catch (PregException $e) {
try {
  return pattern('Foo')->test($subject);
} catch (PatternException $e) {

They both extend RegexException - base for all exceptions thrown by T-Regx. So that's the first thing.

The second exception update - previously, every exception thrown based on preg_last_error() method was RuntimePregException. Now, each error has a dedicated exception, which can be caught separately:

try {
  return preg::match($pattern, $subject);
} catch (BacktrackLimitPregException $exception) {
} catch (Utf8OffsetPregException $exception) {

The detailed list of changes is in ChangeLog.md.

groupBy()

This realase also comes with a brand new method - groupBy() which groups matches by a capturing group (name or index). It can match strings, offsets and also map them with map() and flatMap(). Additionally, it can be chained with filter() to leave out unwanted matches:

return pattern('(\d)(?cm|mm)')->match($strings)
  ->filter(function (Match $match) {
    return $match->group(1)->toInt() % 2 == 0;
  })
  ->groupBy('unit')
  ->map(function (Match $match) {
    return $match->group(1)->toInt() * 100;
  });

0.9.2 - You're in for a treat

Choose a tag to compare

@danon danon released this 12 Jun 16:41

😎 T-Regx The Dinosaur is really proud to announce its first beta version! Despite the beta suffix, it's 100% suitable for production use. It doesn't have any known bugs - check out the issues. There is a few breaking changes (since that's a 0.* version), but there are also a looot of improvements and new feautres.

The detailed list of changes is in ChangeLog.md.

Here's a summary:

  • Breaking changes
    • Refactored entry points - Pattern::of()/pattern() and Pattern::pcre() (see more in ChangeLog.md)
    • Renamed parseInt() to toInt()
    • Removed pattern()->match()->test()/fails(). From now on, use pattern()->test()/fails()
    • Removed is() (see more in ChangeLog.md)
    • Refactored split() (see more in ChangeLog.md)
  • Features
    • Added Match.group().replace() 🔥
    • Added to pattern()->match():
      • fluent(),
        asInt(),
        distinct(),
        groups(),
        offsets()->fluent(),
        group(string)->offsets()->fluent()
    • Added pattern()->forArray()->strict() which throws for invalid values
    • Added Pattern::inject()/Pattern::bind()
  • SafeRegex
    • Added preg::grep_keys() 🔥
  • Other
    • Now MalformedPatternException is thrown, instead of CompileSafeRegexException, when using invalid PCRE syntax.

That's just a handful, the more detailed description of this realease is in ChangeLog.md.

0.9.1

Choose a tag to compare

@danon danon released this 12 Jun 16:42

😎 T-Regx The Dinosaur is proud to announce its second alpha version! It doesn't have any known bugs - it's just missing a few time-consuming features.

What's new in this release:

  • UTF8-safe method textLength() for Match and Match.group()
  • groupsCount() method for Match details - unsurprisingly just counts the groups (without duplicates of named and regular groups)

And more changes, that required a large part of replacing core to be rewritten, to allow more control over unmatched groups:

  • Methods by()->group()->orIgnore() and by()->group()->orElse()
  • Method by()->group()->callback() which accepts MatchGroup as an argument
  • Method by()->group()->orElse() now receives lazy-loaded Match, instead of a less useful - subject

The new features are already described in the documentation at t-regx.com :)