# Regex for labels in ctest\_test

**URL:** https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698
**Category:** Usage
**Tags:** tool:ctest
**Created:** [December 22, 2023, 4:42pm UTC](https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698 "2023-12-22T16:42:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [December 22, 2023, 4:42pm UTC](https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698/1 "2023-12-22T16:42:49Z")

</div>

Hello,

I have several tests described with some of them having multiple labels. I am trying to run tests with multiple labels, like label\_A and label\_B, in ctest\_test(). I am not able to get a regex work for this case, for the LABELS field of ctest\_test(). Have tried a few combinations of POSIX regex, but haven’t been successful. I might be doing something stupid here, Any help would be appreciated ☺

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: [December 22, 2023, 4:48pm UTC](https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698/2 "2023-12-22T16:48:29Z")

</div>

This is probably easiest:

```cmake
set(labels
  "^label1$"
  "^label2$")
string(REPLACE ";" "|" labels "${labels}")
ctest_test(… LABELS "${labels}")

```

---

<div class="post-metadata">

### Author: ![pkiran](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/dc4da7/32.png) [@pkiran](https://discourse.cmake.org/u/pkiran)
#### Post date: [December 23, 2023, 7:37am UTC](https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698/3 "2023-12-23T07:37:11Z")

</div>

Thanks for the reply Ben 🙂  
I am looking to run a set of tests that are intersection of 2 labels. Only if the tests have both the labels, I would like to run them. Is there a way to represent that in posix regex for ctest\_test()

I tried the answer at [regex - Regular Expressions: Is there an AND operator? - Stack Overflow](https://stackoverflow.com/a/469951) , does not help unfortunately.

Something like

```auto
ctest_test( APPEND 
            INCLUDE_LABEL "(?=^label1$)(?=^label2$)" 

```

I get the following error:

```auto
RegularExpression::compile(): ?+* follows nothing.
RegularExpression::compile(): Error in compile.

```

Also to clarify, my add test looks like this

```auto
set_tests_properties(testA PROPERTIES 
      LABELS "label1;label2"

```

---

<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: [December 24, 2023, 1:14am UTC](https://discourse.cmake.org/t/regex-for-labels-in-ctest-test/9698/4 "2023-12-24T01:14:26Z")

</div>

I don’t believe so as each label is (IIRC) tested against the regex individually. Using [this proposed feature](https://gitlab.kitware.com/cmake/cmake/-/issues/25455) with `ctest -N -L label1` and using `sort` and `uniq -d` to craft a test list would probably be the easiest solution.
