File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -171,11 +171,16 @@ impl StringOp {
171
171
let mut prev_is_escaped = false ;
172
172
for curr in pattern_chars {
173
173
match curr {
174
- // Carets are interpreted literally, unless used as character class negation "[^a]"
175
- '^' if prev_is_escaped || !matches ! ( prev, '\\' | '[' ) => {
176
- re_string. push_str ( r"\^" ) ;
177
- }
178
- char => re_string. push ( char) ,
174
+ '^' => match ( prev, prev_is_escaped) {
175
+ // Start of a capturing group
176
+ ( '(' , true ) => re_string. push ( curr) ,
177
+ // Character class negation "[^a]"
178
+ ( '[' , false ) => re_string. push ( curr) ,
179
+ // Explicitly escaped caret
180
+ ( '\\' , false ) => re_string. push ( curr) ,
181
+ _ => re_string. push_str ( r"\^" ) ,
182
+ } ,
183
+ _ => re_string. push ( curr) ,
179
184
}
180
185
181
186
prev_is_escaped = prev == '\\' && !prev_is_escaped;
You can’t perform that action at this time.
0 commit comments