Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/src/history.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
* *New*: Added test for regular expressions with MATCH builtin rule.
-- _Paolo Pastori_

* Fix various regexp issues, allowing for mandatory regular expression
syntax checking, detailed error messages, and improved MATCH rule.
-- _Paolo Pastori_

== Version 5.4.2

Fix detection of Visual Studio 2026 to account for non-native tools being
Expand Down
17 changes: 10 additions & 7 deletions src/engine/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1018,20 +1018,23 @@ LIST * builtin_match( FRAME * frame, int flags )
b2::list_cref patterns( lol_get( frame->args, 0 ) );
for ( auto pattern : patterns )
{
b2::regex::program re( pattern->str() );
b2::regex::program re;
{
// compilation errors print a nice error message and exit
b2::regex::frame_ctx ctx(frame);
re.reset( pattern->str() );
}

/* For each text string to match against. */
b2::list_cref texts( lol_get( frame->args, 1 ) );
for ( auto text : texts )
{
if ( auto re_i = re.search( text->str() ) )
{
/* Find highest parameter */
int top = NSUBEXP-1;
while ( !re_i[top].begin() ) top -= 1;
/* And add all parameters up to highest onto list. */
/* Must have parameters to have results! */
for ( int i = 1; i <= top ; ++i )
/* Find total groups matched */
int tot = re_i.count();
/* And add all catched matches onto result list. */
for ( int i = 1; i <= tot ; ++i )
{
string_append_range( buf, re_i[i].begin(), re_i[i].end() );
result.push_back( object_new( buf->value ) );
Expand Down
Loading