Appendix A. Regular Expressions
In CloudForms Management Engine, regular expressions can be used to search the contents of a file for a specific string for use in a condition. Below are listed the items most commonly used with CloudForms Management Engine to search strings. These are a small subset of all the items available to use in regular expressions. If you are unfamiliar with regular expressions, there are many resources available on the Internet, including www.regular-expressions.info. Note that if you want to search a file, you must collect it as part of a host analysis profile.
Table A.1. Regular Expressions
| Anchors | |
|---|---|
| ^ | start of string |
| $ | end of string |
| Character Classes |
|
| \s | white space including spaces, tabs, and line breaks |
| \S | not white space |
| \d | digit, same as [0-9] |
| \D | not digit |
| \w | word |
| \W | not word |
| Quantifiers | |
| * | 0 or more of preceding characters |
| + | 1 or more of preceding characters |
| ? | 0 or 1 of preceding character |
| Escape Character |
|
| \ | put before a metacharacter to search for that actual character |
| Metacharacters |
|
| ^ [ . $ { * ( \ + ) | ? < > | must be used with the Escape Character if you are searching specifically for it |
| Special characters |
|
| \n | new line |
| \t | tab |
| Groups and Ranges |
|
| . | any character except new line (\n) |
| (a|b) | a or b |
| () | group |
| [abc] | a or b or c |
| [^abc] | not a or b or c |
| [a-q] | letter between a and q |
| [A-Q] | upper case letter between A and Q |
| [0-7] | digit between 0 and 7 |
| Pattern modifiers |
|
| i | case insensitive |
| Other helpers |
|
| .* | swallows text between 2 words |
| \s+ | guarantees minimum of 1 whitespace between 2 words |
| \s* | guarantees 0 or more whitespace between 2 words |
| ^\s* | beginning of line with zero or more whitespace |
| \s+.* | swallows all text and white space between 2 words |
| \d+ | guarantees minimum of 1 number between 2 words |
| <\w> | identical to <[a-zA-Z0-(_]> |
Table A.2. Examples
| Description | Regular Expression |
|---|---|
| ([A-Za-z0-9]+) | Letters, numbers, hyphens |
|
Find the line beginning with | ^sshd:[^:]*:[^:]*:[^:]*:99999: |
|
Verify that | ^\s*PASS_MAX_DAYS\s+([0-9]|[1-8][0-9]|90) |
|
Verify that | /[#]*ROOTPW/i |
| Verify that line in file starts with size and the value after is ⇐ 4096k. | ^\s*size\s+(409[0-6]|40[0-8][0-9]|[123][09]{3}|\d{1,3})k |
|
Find line with string | ^\s*restrict\s+127\.0\.0\.1 |
|
Find an uncommented line that contains | [#]*\/home |

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.