-4

What's the meaning of the symbols ^ and $ in regular expression.

For example :

^[SQBM][0-9]{5,6}$

Thanks

Hugh La Main
  • 39
  • 1
  • 4
  • `^` starts with, `$` ends with. – John Woo Sep 10 '13 at 08:24
  • 1
    See e.g. [Start of String and End of String Anchors](http://www.regular-expressions.info/anchors.html) or read the perlretut [Part 1: The basics: Simple word matching](http://perldoc.perl.org/perlretut.html#Simple-word-matching) – stema Sep 10 '13 at 08:31

2 Answers2

4

^ is beginning of input and $ is the end of it.

e.g.

  • ^[0-9] - everything that starts from a digit
  • [0-9]$ - everything that ends with a digit

And a little bit more detailed description from wiki:

  • ^ Matches the starting position within the string. In line-based tools, it matches the starting position of any line.
  • $ Matches the ending position of the string or the position just before a string-ending newline. In line-based tools, it matches the ending position of any line.
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
1

^ - beginning of text

$ - end end of text

Marcin Szymczak
  • 11,199
  • 5
  • 55
  • 63