Simple library for regular expressions in PHP.
😎 T-Regx The Dinosaur is really proud to announce its release 0.20.2
! It's an immediate release, after a vulnerable 0.20.1
, which we are sorry to say, we accidentally broke support for PHP 7.1 (by using str_contains()
), but it's fixed in 0.20.2
. There is a discussion explaining reasons for deprecation of focus()
https://github.com/T-Regx/T-Regx/discussions/129 - before the focus()
is removed from library, we'll release a separate package with the functionallity.
The detailed list of changes is in ChangeLog.md.
pattern()->match()->remaining()
, as it was a failed idea (in 0.20.0).match()->groupBy()
for a nonexistent group didn't throw NonexistentGroupException
.(?i)
) modifier didn't update the
flags properly, resulting in improper parsing of placeholders in Pattern::inject()
/Pattern::template()
.(?^)
didn't properly unset extended pattern, leading to improper
placeholder @
parsing inside comments.stream()->map()->asInt()
ignored integer-base, assumed base 10.pattern->cut()
which splits string into exactly two parts.pattern()->match()->reduce()
.$flags
parameter to preg::replace_callback()
which was added in PHP 7.4.CompositePattern.chainedReplace()
by using single call to PCRE.Detail.substitute()
.pattern()->replace()->focus()
.The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
😎 T-Regx The Dinosaur is really proud to announce its release 0.19.1
! It's a bug-fixing release. While working on our replacement revamp, we stumbled upon a bug writing our unit tests, believe that; so we decided we needed to fix this ASAP: https://github.com/T-Regx/T-Regx/issues/122
The detailed list of changes is in ChangeLog.md.
[]]
with prepared pattern was parsed incorrectly.[:alpha:]
) with prepared pattern were parsed incorrectly.The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
😎 T-Regx The Dinosaur is really proud to announce its release 0.19.0
! It's a really small release, with the addition of a new argument for replace()->counting()
.
The detailed list of changes is in ChangeLog.md.
BaseDetail
to Structure
Structure
as second parameter to replace()->counting()
The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
😎 T-Regx The Dinosaur is really proud to announce its release 0.18.0
! That's just an intermediate version, that will allow you to upgrade more seamlessly.
We're in the middle of a general rewrite of the Replace Module (the pattern()->replace()
part), and in the meantime, we have to rethink certain ideas. The sad part is, we must let certain methods go, like otherwise()
- leaving room for more exciting new methods. So, for now, let's keep an open mind, to be ready for the next realease refreshed Replace Module. It won't change much, we promise! :)
The detailed list of changes is in ChangeLog.md.
replace()->otherwise()
. Use counting()
instead.replace()->otherwiseReturning()
. Use counting()
instead.replace()->otherwiseThrowing()
. Use counting()
or atLeast()
instead.The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is really proud to announce its release 0.17.0
! We're coming to giga-big-release of 1.0.0
with big steps!
We noticed that interface of FluentMatchPattern
(result of pattern()->match()->fluent()
) and its idea, conceptually, is similar to Java8 streams. Semi-functional programming approach, with terminal statements. We decided it was a good idea to make the name more descriptive, so that, if a dinosaur lover knows Java by some accident, he could find similarities here.
So we just renamed FluentMatchPattern
to Stream
. And also fluent()
method to stream()
.
The detailed list of changes is in ChangeLog.md.
orElseCalling()
didn't throw InvalidReturnValueException
FluentMatchPattern
to Stream
, similar to Java 8 streamsfluent()
to stream()
, similar to Java 8 streamsNoSuchElementFluentException
to NoSuchStreamElementException
IntStream.stream()
The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is really proud to announce its release 0.16.0
! This time, we found out that by simplifying T-Regx internal implementation, we can actually simplify the public interface of the library as well! Cool, isn't it? :D
Currently, when you call pattern()->match()->fluent()
, you receive FluentMatchPattern
(something like Stream
from Java8). However, when you call pattern()->match()->asInt()
and pattern()->match()->offsets()
you also receive FluentMatchPattern
, which behaves slightly in a different way (for example throws different exceptions).
We stoped for a minute a thought - waidaminute, something's wrong, I can feel it. So we decided that what must be done is fluent()
must be separated from asInt()
and offsets()
. That's how IntStream
was born.
The detailed list of changes is in ChangeLog.md.
Methods asInt()
and offsets()
return IntStream
instead of FluentMatchPattern
.
Removed FluentMatchPatternException
. In case of asInt()
, InvalidIntegerTypeException
is thrown instead.
Updated the rules when exceptions are thrown from asInt()
, offsets()
and fluent()
:
IntStream
:
pattern()->match()->asInt()
throws SubjectNotMatchedException
pattern()->match()->offsets()
throws SubjectNotMatchedException
pattern()->match()->group()->asInt()
throws SubjectNotMatchedException
or GroupNotMatchedException
pattern()->match()->group()->offsets()
throws SubjectNotMatchedException
or GroupNotMatchedException
FluentMatchPattern
:
pattern()->match()->fluent()
throws NoSuchElementFluentException
pattern()->match()->asInt()->fluent()
throws NoSuchElementFluentException
pattern()->match()->offsets()->fluent()
throws NoSuchElementFluentException
Basically, MatchPattern
and IntStream
throw match-related exceptions (SubjectNotMatchedException
or GroupNotMatchedException
), whereas FluentMatchPattern
throws fluent-related
exception: NoSuchElementFluentException
.
Updated exception messages from asInt()
, offsets()
and fluent()
.
MatchPatternInterface
is no longer part of T-Regx public API.
The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is really proud to announce its release 0.15.0
! We're coming to giga-big-release of 1.0.0
with really big steps!
This time, we look around our dinosaur friendly projects, and we noticed that most users use Pattern::template()
with just one call, and need to call build()
at the end. That's not very elegant, T-Regx the dinousaur said, and we agree! That's why we refactored. The API a little bit.
The detailed list of changes is also in ChangeLog.md.
Previously, to create a template, you needed to call Pattern::template()->something()->build()
. This is looong and inconvenient. Here's what we did.
Pattern::template()
to Pattern::builder()
. So if you need to build many elements, you can go
Pattern::builder($yourTemplateHere)
->literal($value)
->mask($mask, $keys)
->build();
Pattern::template()
, which works similarly to Pattern::builder()
but allows only one chain:
$pattern = Pattern::template('^@$')->literal('Hi!'); // that's it
The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is proud to announce its release 0.14.0
! That's a quick release with the update of a few names regarding Pattern::compose()
. allMatch()
wasn't a really good name, was it?
The detailed list of changes is also in ChangeLog.md.
Breaking changes
Pattern::compose()->allMatch()
was horrible, we renamed it to testAll()
Pattern::compose()->anyMatches()
wasn't good either, we renamed it to testAny()
So, if you want to test a composite pattern, you just type Pattern::compose()->test
and choose Any()
or All()
:)
Pattern::compose()->chainedRemove()
to prune()
, because "chained remove" was basically prune, just with a more scary name ?Features
Pattern::compose()->failAny()
, returning true
if any of the patterns didn't match the subjectPattern::compose()->failAll()
, returning true
if all the patterns didn't match the subjectSame as before, if you'd like to check if your composite pattern fails a subject, just type Pattern::compose()->fail
and choose Any()
or All()
:)
The detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is really proud to announce its release 0.13.8
! We're coming to giga-big-release of 1.0.0
with big steps!
In this release, we took a look at how PHP parses the patterns, before passing them to PCRE, and it shocked us! that it does so negligent. Perfectly valid patterns are reported as invalid by PHP, because of improper parsing.
Example:
/\c\/
is marked as invalid in PHP. So is /\Q\/
and other valid patterns (like comment groups and comments in exnteded mode)In this release we handled this bug, so that pattern()
, Pattern::of()
, Pattern::mask()
and Pattern::template()
correctly understand these patterns. We parse the whole pattern, and we guess if it would be reported by PHP, and we fill it with padding, to make it digest by PHP, while keeping the meritoric value. For example, T-Regx changes \c\
to \c\{1}
which is the same thing in regular expression, but PHP reports the first as invalid.
You, as a user of T-Regx don't have to worry about it at all. Simply use you regular expression, and let T-Regx handle it for you.
The detailed list of changes is in ChangeLog.md.
Pattern::inject('()(?)')
failed parsing\c\
as invalid entity, all T-Regx entry points correctly recognize it as valid\Q\
as invalid entity, all T-Regx entry points correctly recognize it as valid(?#\
as invalid entity, all T-Regx entry points correctly recognize it as valid#\
as invalid entity in X
tended mode, all T-Regx entry points correctly recognize it as validOptional.map()
, which resembles Java 8 optionals.pattern()->match()->asInt()->findFirst()->orElse()
receive NotMatched
argumentpattern()->match()->asInt()->findNth()->orElse()
receive NotMatched
argumentpattern()->match()->offsets()->findFirst()->orElse()
receive NotMatched
argumentpattern()->match()->offsets()->findNth()->orElse()
receive NotMatched
argumentThe detailed list of changes is also in ChangeLog.md.
Rawrrrr!
? T-Regx The Dinosaur is really proud to announce its release 0.13.5
! We're coming to giga-big-release of 1.0.0
with big steps!
The detailed list of changes is in ChangeLog.md.
Pattern::pcre()
, so it's more concise, and doesn't use builder()
method.Pattern::alteration()
which allows building Pattern
with just an alteration group.
Pattern::alteration(['foo', 'bar'])
is /(?:foo|bar)/
Pattern::template()->alteration()
false
as an alteration value didn't throw \InvalidArgumentException
.The detailed list of changes is also in ChangeLog.md.
Rawrrrr!