Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression using '$' sign and '^'

Tags:

regex

Can some body explain the difference between below expressions please?

[0-9]{1,3}:[0-5][0-9]

^([0-9]{1,3}:[0-5][0-9])$

I don't get the exact usage of ^ sign and $ sign in regular expressions.

I observe that If I write the second expression as below, it didn't make any difference.

^([0-9]{1,3}):([0-5][0-9])$

like image 305
ravindrab Avatar asked Jul 14 '26 19:07

ravindrab


1 Answers

examples explain it clear:

^     : matches the beginning of a line
$     : matches the end of a line

"^foo$" : matches "foo", but not " foo" or "xxfooyy"
"foo$"  : matches "foo",  " foo" or "xxfoo" but not "foobar"
"^foo"  : matches "foo",  "fooyy" or "foo " but not "xfoo"
"foo"   : matches "foo",  " foo" or "xxfooyy"
like image 184
Kent Avatar answered Jul 21 '26 03:07

Kent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!