|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * operating/create-use-collections.adoc |
| 4 | +:_mod-docs-content-type: CONCEPT |
| 5 | +[id="using-regular-expression_{context}"] |
| 6 | += Using regular expressions |
| 7 | + |
| 8 | +{product-title-short} uses regular expressions in some areas of the portal, including when you configure collections to include or exclude deployments. |
| 9 | + |
| 10 | +For example, when configuring a collection, you can use regular expressions to search for a deployment. This option is useful if you do not know the exact name of the deployment. A regular expression is a string of letters, numbers, and symbols that defines a pattern. {product-title-short} uses this pattern to match characters or groups of characters and return results. For regular expressions, note the following guidelines: |
| 11 | + |
| 12 | +* link:https://github.com/google/re2/wiki/Syntax[RE2 syntax] is supported. |
| 13 | +* Perl syntax is not supported. |
| 14 | +* Testing your regular expressions syntax is helpful, for example, by using a site such as link:https://regex101.com/[https://regex101.com/]. Select *Golang* as the flavor. |
| 15 | +
|
| 16 | +[NOTE] |
| 17 | +==== |
| 18 | +The following examples assume naming conventions are followed where production clusters contain the word `prod` in the name. |
| 19 | +==== |
| 20 | + |
| 21 | +.Regular expressions example to create a collection of production clusters |
| 22 | + |
| 23 | +. In *Collection rules*, select *Clusters with names matching*. |
| 24 | +. From the drop-down list, select *A regex value of* and enter the following text: |
| 25 | ++ |
| 26 | +---- |
| 27 | +^prod.* |
| 28 | +---- |
| 29 | + |
| 30 | +.Regular expressions example to create a collection of non-production clusters |
| 31 | + |
| 32 | +With RE2 syntax, you cannot match by using negative lookahead, meaning that you cannot direct regular expressions to match if an element is *not* present. As a workaround, you can use regular expressions to match when the word `prod` does not appear in the cluster name; that is, to match if the letters `p`, `r`, `o`, and `d` do not appear in sequence. |
| 33 | + |
| 34 | +. In *Collection rules*, select *Clusters with names matching*. |
| 35 | +. From the drop-down list, select *A regex value of* and enter the following text: |
| 36 | ++ |
| 37 | +---- |
| 38 | +^[^p]*(p([^r]|$|r([^o]|$|o([^d]|$))))*[^p]*$ |
| 39 | +---- |
| 40 | +
|
| 41 | +.Regular expressions example to create a collection that matches all entities in the cluster, namespace, and deployments hierarchy |
| 42 | +
|
| 43 | +. In *Collection rules*, select *Deployments with names matching*. |
| 44 | +.. From the drop-down list, select *A regex value of* and enter `.*`. |
| 45 | +. Select *Namespaces with names matching*. |
| 46 | +.. From the drop-down list, select *A regex value of* and enter `.*`. |
| 47 | +. Select *Clusters with names matching*. |
| 48 | +.. From the drop-down list, select *A regex value of* and enter `.*`. |
| 49 | + |
| 50 | +.Regular expressions example to create a collection that includes a named deployment and database and specific labels |
| 51 | + |
| 52 | +The following example provides the steps for configuring a collection for a medical application. In this example, you want your collection to include the `reporting` deployment, a database called `patient-db`, and you want to select namespaces with labels where `key = kubernetes.io/metadata.name` and `value = medical`. For this example, perform the following steps: |
| 53 | + |
| 54 | +. In *Collection rules*, select *Deployments with names matching*. |
| 55 | +. Click *An exact value of* and enter *reporting*. |
| 56 | +. Click *OR*. |
| 57 | +. Click *A regex value of* and enter `.*-db` to select all deployments with a name ending in `db` in your environment. The `regex value` option uses regular expressions for pattern matching. For regular expressions, link:https://github.com/google/re2/wiki/Syntax[RE2 syntax] is supported. Perl syntax is not supported. The panel on the right might display databases that you do not want to include. You can exclude those databases by using additional filters. For example: |
| 58 | +.. Filter by namespace labels by clicking *Namespaces with labels matching exactly* and entering `kubernetes.io/metadata.name=medical` to include only deployments in the namespace that is labeled `medical`. |
| 59 | +.. If you know the name of the namespace, click *Namespaces with names matching* and enter the name. |
0 commit comments