Skip to content

Commit 6be77a3

Browse files
committed
Added Anchors to Pattern
1 parent de001ef commit 6be77a3

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Rubberduck.RegexAssistant/Pattern.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ class Pattern
1111
IRegularExpression RootExpression;
1212
MatcherFlags Flags;
1313

14+
private readonly bool _hasStartAnchor;
15+
private readonly bool _hasEndAnchor;
16+
1417
public Pattern(string expression, bool ignoreCase, bool global)
1518
{
1619
Flags = ignoreCase ? MatcherFlags.IgnoreCase : 0;
1720
Flags = global ? Flags | MatcherFlags.Global : Flags;
1821

19-
RootExpression = RegularExpression.Parse(expression);
22+
_hasEndAnchor = expression[expression.Length - 1].Equals('$');
23+
_hasStartAnchor = expression[0].Equals('^');
24+
25+
int start = _hasStartAnchor ? 1 : 0;
26+
int end = (_hasEndAnchor ? 1 : 0) + start + 1;
27+
RootExpression = RegularExpression.Parse(expression.Substring(start, expression.Length - end));
2028
}
2129

2230
}

0 commit comments

Comments
 (0)