Simple library for regular expressions in PHP.
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:
Pattern::of()
to new Pattern()
.Pattern::template()
, Pattern::alteration()
, Pattern::inject()
) will be in separate package (not yet published)start()
, byteStart()
renamed to offset()
, byteOffset()
Group
object, now access groups by methods: Detail.group()
, Detail.groupOrNull()
, Detail.groupOffset()
, Detail.groupExists()
, Detail.groupMatched()
.MalformedPatternException
-> SyntaxException
, and others...)Please, share feedback!
😎 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.
The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
^]
.The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
0.41.0
T-Regx officially supports PHP 8.2.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 acceptedPattern::inject($pattern, $figures, 'n')
is now acceptedPattern::template($pattern, 'n')
is now acceptedPattern::builder($pattern, 'n')
is now acceptedPattern::literal($text, 'n')
is now acceptedPattern::alteration($texts, 'n')
is now acceptedPattern::mask($mask, $keywords, 'n')
is now acceptedPattern::list()
now accepts patterns with n
modifierAdded full support for n
modifier in PcrePattern
PcrePattern::of("/$pattern/n", )
is now acceptedPcrePattern::inject("/$pattern/n", $figures)
is now acceptedPcrePattern::template("/$pattern/n")
is now acceptedPcrePattern::builder("/$pattern/n")
is now acceptedPattern
.
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!
😎 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
SubjectNotMatchedException.getSubject()
.ChainedReplace
, PatternTemplate
and TemplateBuilder
to other namespaces.MalformedPatternException
message Null byte in regex
to Pattern may not contain null-byte
.MalformedPatternException
message ...unexpected delimiter '\0'
to ...null-byte delimiter
.Bug fixes
mask()
didn't take modifiers into account when running validation
Pattern::mask()
Pattern::template()->mask()
Pattern::builder()->mask()
PcrePattern::template()->mask()
PcrePattern::builder()->mask()
Features
Added public modifier constants to Pattern
.
Pattern::CASE_INSENSITIVE
Pattern::UNICODE
Pattern::MULTILINE
Pattern::SINGLELINE
Pattern::IGNORE_WHITESPACE
Pattern::ANCHORED
Pattern::GREEDYNESS_INVERTED
Pattern::RESTRICTIVE_ESCAPE
Pattern::DUPLICATE_NAMES
Pattern::DOLLAR_ENDONLY
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
PlaceholderFigureException
now extend correctly implements PatternException
.The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
Pattern.forArray().filter()
. Use Pattern.filter()
instead.Pattern.forArray().filterAssoc()
.Pattern.forArray().filterByKeys()
.PatternList.chainedReplace()
to PatternList.replace()
PcrePattern
with delimiter \n
, \v
, \f
, t
didn't throw
appropriate MalformedPatternException
Pattern.filter()
, which filters subjects which match the pattern (exactly like previous Pattern.forArray().filter()
).Pattern.reject()
, which filters subjects which do not match the pattern.\RuntimeException
, instead of \Exception
.The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
Pattern.replace()
functionality.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.replace().callback()
no longer accepts Detail
or Group
as a return value.Migration guide:
focus()
- To continue using functinallity, use a separate package.Group.substitute()
- To continue using functinallity, use a separate package.replace().by()
- use replace().callback()
or replace().withGroup()
replace().counting()
- use replace.count()
replace().all()
- omit call to all()
replace().callback()
return type - return Detail.text()
or Group.text()
as a return value.ReplaceLimit
to Replace
.The detailed list of changes is in ChangeLog.md.
Rawrrrrrrr!
😎 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.
PatternList.count()
, which allows to count occurrances of many patterns in a subject.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!
😎 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!