T Regx Versions Save

Simple library for regular expressions in PHP.

1.0.0-alpha1

1 week ago

The interface of this version is still subject to change, although I'll try to minimize breaking changes at this point.

Biggest changes since last release:

  • Changed Pattern::of() to new Pattern().
  • Prepared patterns (so Pattern::template(), Pattern::alteration(), Pattern::inject()) will be in separate package (not yet published)
  • start(), byteStart() renamed to offset(), byteOffset()
  • Removed Group object, now access groups by methods: Detail.group(), Detail.groupOrNull(), Detail.groupOffset(), Detail.groupExists(), Detail.groupMatched().
  • Renamed exceptions (MalformedPatternException -> SyntaxException, and others...)

Please, share feedback!

0.41.4

11 months ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.41.4!

We've spent time on improving the performance of the library as well as handling of the input regular expressions. We've found another two bottlenecks and successfully fixed them.

Additionally, we're updating PHP constraint for composer packages, to include higher versions of PHP

The detailed list of changes is in ChangeLog.md.

  • Other
    • Relaxed composer PHP version requirement up.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.41.2

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.41.2!

Another two weeks have passed, and this time we spent them on increasing the performance of library. There were a few obvious bottlenecks that we overlooked while developing T-Regx, mostly in the regular expression parser, horrible stuff, but we believe we managed to bring back up the standards now.

This release doesn't bring in any new features.

The detailed list of changes is in ChangeLog.md.

  • Bug fixes
    • Fixed a bug with improper parsing of character classes starting with ^].
    • Fixed a bug with improper client error handlers, when user-supplied callbacks threw exceptions.
  • Performance
    • Increased pattern instantiating performance by parsing continuous literal figures as one entity.
    • Additional performance optimisations with usage of xDebug profiler and QCacheGrind.
    • Increased performance of parsing certain features by using PHP built-in functions, instead of loops.
    • Increased performance of prepared patterns by looking up strategies by hashtable.
    • Reimplemented some of internal parser logic without unnecessary conditions and iterations.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.41.1

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.41.1!

We've been recently notified about a certain buggy behaviour, when T-Regx was used in an environment with overriden error handlers, which tends to be the case in Laravel applications, but also other applications. Needlessly to say, we've fixed the issue and T-Regx continues to work as before, even in an environment with overriden error handlers.

The detailed list of changes is in ChangeLog.md.

  • Features
    • Updated internal error handling, so T-Regx works in an environment with overriden error handler.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.41.0

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.41.0!

We've been working our fingers to the bone before official release of PHP 8.2, and with it comes the new and shiny /n modifier - "no auto capture". Some of us have been waiting for a long time, and in T-Regx we're not discriminating, and each PHP version should work the same. Because of that, we're backporting /n modifier to every PHP version supported. So if you're using T-Regx on PHP as old as 7.1, you are free to use /n in Pattern and PcrePattern to its fullest. It's completely supported. That feature is available as of version 0.41.0.

The modifier n can be used on each PHP version (since T-Regx 0.41.0) seamlessly. That means, any usage of modifier n in any part of the library (including the regular expression itself) works out of the box, as if the library was running on PHP 8.2.

The detailed list of changes is in ChangeLog.md.

  • Features
    • Since 0.41.0 T-Regx officially supports PHP 8.2.
    • Added full support for n modifier for every supported PHP version: 7.1 - 8.2
      • Despite modifier /n being only valid in vanilla regexp in PHP only since 8.2, modifier /n is fully supported in T-Regx in each PHP version.

      • Added full support for n modifier in Pattern

        • Pattern::of($pattern, 'n') is now accepted
        • Pattern::inject($pattern, $figures, 'n') is now accepted
        • Pattern::template($pattern, 'n') is now accepted
        • Pattern::builder($pattern, 'n') is now accepted
        • Pattern::literal($text, 'n') is now accepted
        • Pattern::alteration($texts, 'n') is now accepted
        • Pattern::mask($mask, $keywords, 'n') is now accepted
        • Pattern::list() now accepts patterns with n modifier
      • Added full support for n modifier in PcrePattern

        • PcrePattern::of("/$pattern/n", ) is now accepted
        • PcrePattern::inject("/$pattern/n", $figures) is now accepted
        • PcrePattern::template("/$pattern/n") is now accepted
        • PcrePattern::builder("/$pattern/n") is now accepted
    • Added public modifier constant to Pattern.
      • Added Pattern::NO_AUTOCAPTURE

        From now on, patterns can be constructed with such constants, for example:

        Pattern::of('^(foo)$', Pattern::NO_AUTOCAPTURE)
        

        String literal modifiers continue to work as before

        Pattern::of('^(foo)$', 'n');
        

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.40.0

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.40.0!

Release of 0.40.0 is an intermediate release - we're working our fingers to the bone before official release of PHP 8.2, and with it comes the new and shiny /n modifier - "no auto capture". Some of us have been waiting for a long time, and in T-Regx we're not discriminating, and each PHP version should work the same. Because of that, we're backporting /n modifier to every PHP version supported. So if you're using T-Regx on PHP as old as 7.1, you are free to use /n in Pattern and PcrePattern to its fullest. It's completely supported. That feature will be available in version 0.41.0, which will be released in a couple of hours. But before that, we're releasing all changes that were made during the development of /n backport.

The detailed list of changes is in ChangeLog.md.

  • Breaking changes

    • Removed SubjectNotMatchedException.getSubject().
    • Moved ChainedReplace, PatternTemplate and TemplateBuilder to other namespaces.
    • Updated MalformedPatternException message Null byte in regex to Pattern may not contain null-byte.
    • Updated MalformedPatternException message ...unexpected delimiter '\0' to ...null-byte delimiter.
  • Bug fixes

    • Fixed a bug when using prepared patterns with mask() didn't take modifiers into account when running validation
      • Fixed the bug in Pattern::mask()
      • Fixed the bug in Pattern::template()->mask()
      • Fixed the bug in Pattern::builder()->mask()
      • Fixed the bug in PcrePattern::template()->mask()
      • Fixed the bug in PcrePattern::builder()->mask()
  • Features

    • Added public modifier constants to Pattern.

      • Added Pattern::CASE_INSENSITIVE
      • Added Pattern::UNICODE
      • Added Pattern::MULTILINE
      • Added Pattern::SINGLELINE
      • Added Pattern::IGNORE_WHITESPACE
      • Added Pattern::ANCHORED
      • Added Pattern::GREEDYNESS_INVERTED
      • Added Pattern::RESTRICTIVE_ESCAPE
      • Added Pattern::DUPLICATE_NAMES
      • Added Pattern::DOLLAR_ENDONLY
      • Added Pattern::STUDY

      From now on, patterns can be constructed with such constants, for example:

      Pattern::of('^foo$', Pattern::CASE_INSENSITIVE . Pattern::MULTILINE)
      

      String literal modifiers continue to work as before

      Pattern::of('^foo$', 'im');
      
  • Other

    • Exception PlaceholderFigureException now extend correctly implements PatternException.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.39.0

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.39.0!

Why PHP programmers tend to not filter arrays by regular expressions? Probably because preg_filter() doesn't filter arrays (it actually replaces, like preg_replace()), and the real function to filter arrays is preg_grep(), but who would know that? Yuk! Hence we're adding Pattern.filter() and Pattern.reject() methods, which accept array, and filter it - leaving of either subjects that match the pattern, or subejcts that don't match the pattern.

Additionally, we noticed that T-Regx users felt obligated to catch library exceptions, when using T-Regx API, but frankly, the intention of the library was never to practice exception-driven-development, so we changed all T-Regx public exceptions to RuntimeException, to emphasise that catching those exceptions isn't necessary.

The detailed list of changes is in ChangeLog.md.

  • Breaking changes
    • Removed Pattern.forArray().filter(). Use Pattern.filter() instead.
    • Removed Pattern.forArray().filterAssoc().
    • Removed Pattern.forArray().filterByKeys().
    • Renamed PatternList.chainedReplace() to PatternList.replace()
  • Bug fixes
    • Fixed a bug when using PcrePattern with delimiter \n, \v, \f, t didn't throw appropriate MalformedPatternException
  • Features
    • Added Pattern.filter(), which filters subjects which match the pattern (exactly like previous Pattern.forArray().filter()).
    • Added Pattern.reject(), which filters subjects which do not match the pattern.
  • Other
    • Public exceptions now extend \RuntimeException, instead of \Exception.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.38.0

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.38.0!

Previous state of replacing API in T-Regx was, frankly, hopeless. It was full of chainable, complex interface, polymorphic instances, unhelpful names, reading count required passing an anonymous function to counting() - it was horrible. We've started working on a revamp 6 months ago, simulateneuously delivering other updates, and today we're proud to say the replacing API revamp is complete. We removed horrible by() function, it functionallity is now available through callback()/withGroup() methods. We removed counting() callback interface, for a more object-oriented Replace.count() call, which is performance optimized. That is, when Replace.count() is called on its own, it will perform a global search, counting values, but if Replace.with() (or other replacing function) is called, then its amount is used and further calls to Replace.count() will not perform additional calls. That way the user can freely use Replace.count() without worying about what calls will do what. Chainable interface was minimized to the absolute minimum - nothing is chainable, except for limit(int) method. There is also no polymorphic APIs, which greatly increase the readability of the API and its cohesion.

The newly revamped replacing API:

/**
 * Instantiate your pattern
 */
$pattern = Pattern::of('\d+');

/**
 * Match the pattern against the subject
 */
$replace = $pattern->replace("My numbers are: 12, 13, 14");

/**
 * Replace occurrances of the pattern in the subject
 */
$replace->callback(fn(Detail $detail) => "X");

/**
 * Count the replacements performed
 */
echo "I replaced " . $replace->count() . " occurrences";

The detailed list of changes is in ChangeLog.md.

  • Breaking changes
    • Revamped Pattern.replace() functionality.
    • Removed focus() and substitute() - useful feature, however it proved to be unreliable when used with look-aheads, look-behinds and \K resets. The functionallity is available through a separate "t-regx" package.
    • Callback in replace().callback() no longer accepts Detail or Group as a return value.

Migration guide:

  • Removed focus() - To continue using functinallity, use a separate package.
  • Removed Group.substitute() - To continue using functinallity, use a separate package.
  • Removed replace().by() - use replace().callback() or replace().withGroup()
  • Removed replace().counting() - use replace.count()
  • Removed replace().all() - omit call to all()
  • Updated replace().callback() return type - return Detail.text() or Group.text() as a return value.
  • Renamed ReplaceLimit to Replace.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.37.1

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.37.1!

This is an intermediate step into our long planned goal of T-Regx having UTF-8 enabled by default, out of the box. We are working on proper unicode and ascii group names, to continue supporting PCRE as well as PCRE2, and having @ placeholder in group names isn't allowed. So we made a fix, so that proper MalformedPatternException is thrown, instead of PlaceholderFigureException.

The detailed list of changes is in ChangeLog.md.

  • Features
    • Add PatternList.count(), which allows to count occurrances of many patterns in a subject.
  • Bug fixes
    • Corrected prepared patterns in malformed patterns.

      When malformed pattern is used, foo(?<bar@cat>door) (because of unallowed @ character in the group name), previously T-Regx would treat @ as a placeholder, and inject a figure into it. Currently, T-Regx ignores @ character in the group name, so PlaceholderFigureException is not thrown, but MalformedPatternException is thrown instead.

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!

0.37.0

1 year ago

😎 T-Regx The Dinosaur is really proud to announce its release 0.37.0! We also would like to mention previous releases, 0.34.2, 0.35.0 and 0.36.0.

Most notably, we're making certain implementations of public interfaces as internal parts of the library. So for example, while \TRegx\CleanRegex\Match\Detail remains public, its implementations (MatchDetail and LazyDetail) are moved to internal namespace, and should not be used directly. They are still being passed to clients code, so you will see it for example with get_class(), but you should not rely on it. We're also deprecating ReplaceDetail and their exclusive methods like modifiedSubject() and other replacement-tracking methods. We also renamed certain methods, for example flatMapAssoc() to toMap(), and Pattern.compose() to Pattern.list().

And by the way, we're working on a new, shiny version of t-regx.com, it will be super cool!

The detailed list of changes is in ChangeLog.md.

Rawrrrrrrr!