Anchors
Anchors help us to enforce the beginning or ending of a string or line and make sure that the expression will only match if everything is covered, instead of just parts of the string to test.
begin/starts with
begin with / starts with
Forcing the string to start is probably most of the time a great idea. For example, try matching an email
address. You certainly don't want to match @[email protected]
just because a part of it is correct.
But try for yourself. Remove the starts with
anchor and play around.
Note: begin with
is a synonym and behaves just like starts with
.
Example query:
starts with literally "match"
SRL Query is matching!
SRL Query is not matching.
The SRL Query contains an error:
Whoops... you may have found a bug.
Generated Regular Expression:
must end
must end
Just like the above, you often want to force the string to end. must end
will stop matching if
the string does not end after the given match.
Example query:
literally "match" must end