35

When I use this code:

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

I get DTH201510080900.xlsx

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Maria Torres
  • 389
  • 1
  • 4
  • 5

2 Answers2

111
  • ^ 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.

maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
zedfoxus
  • 35,121
  • 5
  • 64
  • 63
  • what about if you only have `^` or `$`? e.g. I am seeing this pattern `.*\\.v$` and trying to figure out what it means (and why it doesn't have `^`). – Charlie Parker Sep 09 '22 at 19:47
  • @CharlieParker take a peek at https://regex101.com/r/80wecX/1. Move your mouse over the regex and it'll tell you what `.*\\.v$` matches. https://regexr.com/ site is a good one to learn regex as well. – zedfoxus Sep 10 '22 at 02:53
30
"^.*$"

literally just means select everything

"^"  // anchors to the beginning of the line
".*" // zero or more of any character
"$"  // anchors to end of line
maraaaaaaaa
  • 7,749
  • 2
  • 22
  • 37
  • 1
    what about if you only have `^` or `$`? e.g. I am seeing this pattern `.*\\.v$` and trying to figure out what it means (and why it doesn't have `^`). – Charlie Parker Sep 09 '22 at 19:47
  • @CharlieParker `^` is beginning of the line and `$` is end of the line. So if you have pattern: `xyz$`, it will match the value: `abcxyz`. However pattern: `^xyz$` will not match. Then pattern: `^abc` will also match value: `abcxyz` and pattern: `^abc$` will not. – maraaaaaaaa Sep 09 '22 at 21:03