Assertions are the boundaries / anchors, which mark the beginnings and endings of words and texts. The lookaround patterns are also assertions.
The caret ^
and dollar $
characters are called anchors. They don't match any characters but match a well-determined position of beginning or end of a text/line.
The caret ^
matches the beginning of a text.
I am at peace with all that has happened, is happening, and will happen
I am at peace with all that has happened, is happening, and will happen
The dollar $
matches the end of a text / line.
I am at peace with all that has happened, is happening, and will happen
I am at peace with all that has happened, is happening, and will happen
If the multiline flag is set to true, it could match the beginning of any line in a multiline text.
Today, I am brimming with energy and overflowing with joy
Each day of my life is filled with joy and love
I find opportunities to be kind and caring everywhere I look
With the flags m
and g
, it would match all the line beginnings.
Today, I am brimming with energy and overflowing with joy Each day of my life is filled with joy and love I find opportunities to be kind and caring everywhere I look
If the multiline flag is set to true, it could match the end of any line in a multiline text.
Today, I am brimming with energy and overflowing with joy
Each day of my life is filled with joy and love
I find opportunities to be kind and caring everywhere I look
With the flags m
and g
, it would match all the line endings.
Today, I am brimming with energy and overflowing with joy Each day of my life is filled with joy and love I find opportunities to be kind and caring everywhere I look
\b
matches the position where a word character is not preceded or followed by another word character. In other words, it simply matches the beginning/end of a word.
Lenovo Z6 Pro, releasing on 23rd April, has Snapdragon 855, 12GB of RAM, 4 cameras and a 4045 mAh battery. It'll cost $800.85 after a 15% discount.
\B
matches a non-word boundary. In other words, it matches the positions that are not the beginning/end of a word.
Note these two assertions, like ^
and $
, does not match any character but only marks the position of the characters.
Lenovo Z6 Pro, releasing on 23rd April, has Snapdragon 855, 12GB of RAM, 4 cameras and a 4045 mAh battery. It'll cost $800.85 after a 15% discount.