# Match dot in regex

**URL:** <https://discourse.cmake.org/t/match-dot-in-regex/6420>\
**Category:** Code\
**Created:** [September 6, 2022, 12:12pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420 "2022-09-06T12:12:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![martijntje](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Post date:** [September 6, 2022, 12:12pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420/1 "2022-09-06T12:12:35Z")

</div>

I’m having some issue getting CMake to match a literal dot in a regex expression. The following regex works, but doesn’t match a dot:

`file(STRINGS "${INPUT_FILE}" VERSION_BRANCH_FRIENDLY REGEX "^[\t]*#define[\t]+VERSION_BRANCH_FRIENDLY[\t]+\"[a-zA-Z0-9_\\-]+\".*$")`

If I add a dot to the match it does not match anymore, I’ve tried the following:

`file(STRINGS "${INPUT_FILE}" VERSION_BRANCH_FRIENDLY REGEX "^[\t]*#define[\t]+VERSION_BRANCH_FRIENDLY[\t]+\"[a-zA-Z0-9_\\-.]+\".*$")`

This tells me the regex failed to compile. Escaping the dot with either one or two backslashes makes it compile but not match anything. How can I match a dot with CMake?

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [September 6, 2022, 12:22pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420/2 "2022-09-06T12:22:42Z")

</div>

Character `-` inside `[]` **must be** the **first** or the **last** character of the range when not used to specify a range (as specified in the [Regex Specification](https://cmake.org/cmake/help/git-master/command/string.html#regex-specification)).

---

<div class="post-metadata">

**Author:** ![martijntje](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/838e76/32.png) [@martijntje](https://discourse.cmake.org/u/martijntje)\
**Post date:** [September 6, 2022, 12:26pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420/3 "2022-09-06T12:26:02Z")

</div>

My, that’s surprising behaviour, given that it’s already escaped. This does solve the issue. Thanks!

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [September 6, 2022, 1:11pm UTC](https://discourse.cmake.org/t/match-dot-in-regex/6420/4 "2022-09-06T13:11:04Z")

</div>

FWIW, this behavior isn’t specific to CMake’s regexes; just about every syntax supporting `[-]` requires `-` as `-` (versus “between the adjacent characters”) requires it be at one end or the other.
