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
12 changes: 12 additions & 0 deletions std/regex/internal/tests.d
Original file line number Diff line number Diff line change
Expand Up @@ -1106,3 +1106,15 @@ alias Sequence(int B, int E) = staticIota!(B, E);
auto e = collectException!RegexException(regex(q"<[^]>"));
assert(e.msg.canFind("no operand for '^'"), e.msg);
}

// bugzilla 17673
@safe unittest
{
string str = `<">`;
string[] regexps = ["abc", "\"|x"];
auto regexp = regex(regexps);
auto c = matchFirst(str, regexp);
assert(c);
assert(c.whichPattern == 2);
}

8 changes: 7 additions & 1 deletion std/regex/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,15 @@ if (isSomeString!(S))
app.put("|");
app.put("(?:");
app.put(patterns[i]);
// terminator for the pattern
// to detect if the pattern unexpectedly ends
app.put("\\");
app.put(cast(dchar)(privateUseStart+i)); // special end marker
app.put(cast(dchar)(privateUseStart+i));
app.put(")");
// another one to return correct whichPattern
// for all of potential alternatives in the patterns[i]
app.put("\\");
app.put(cast(dchar)(privateUseStart+i));
}
pat = app.data;
}
Expand Down