26

When I use this code:

'DTH' + @fileDate + '^.*$' 

I get DTH201510080900.xlsx

What does ^.*$ do? Does that give me the 0900 time?

Cœur
  • 32,421
  • 21
  • 173
  • 232
Maria Torres
  • 283
  • 1
  • 3
  • 5
  • 3
    http://www.regular-expressions.info/quickstart.html – Felix Kling Oct 08 '15 at 17:25
  • 2
    Are you concatening it to be a regex? If so the character `^` is invalid. –  Oct 08 '15 at 17:28
  • OP - if you have the ability to do so and if you found one of the answers valuable, please go ahead and mark them as accepted to bring closure to your question. – zedfoxus Oct 09 '15 at 04:08

2 Answers2

80
  • ^ matches position just before the first character of the string
  • $ matches position just after the last character of the string
  • . matches a single character. Does not matter what character it is, except newline
  • * matches preceding match zero or more times

So, ^.*$ means - match, from beginning to end, any character that appears zero or more times. Basically, that means - match everything from start to end of the string. This regex pattern is not very useful.

Let's take a regex pattern that may be a bit useful. Let's say I have two strings The bat of Matt Jones and Matthew's last name is Jones. The pattern ^Matt.*Jones$ will match Matthew's last name is Jones. Why? The pattern says - the string should start with Matt and end with Jones and there can be zero or more characters (any characters) in between them.

Feel free to use an online tool like https://regex101.com/ to test out regex patterns and strings.

maksymiuk
  • 6,444
  • 2
  • 17
  • 31
zedfoxus
  • 28,612
  • 4
  • 47
  • 53
25
"^.*$"

literally just means select everything

"^"  // anchors to the beginning of the line
".*" // zero or more of any character
"$"  // anchors to end of line
maksymiuk
  • 6,444
  • 2
  • 17
  • 31