Programming

Character Representation

The following character combinations represent specific character and numeric values.

 Operator Usage `\a` Alarm (beep) `\b` Backspace `\e` Escape `\f` Form feed `\n` New line `\r` Carriage return `\t` Horizontal tab `\v` Vertical tab `\oN` or `\o{N}` Character of octal value `N` `\xN` or `\x{N}` Character of hexadecimal value `N` `\char` If a character has special meaning in a regular expression, precede it with backslash (`\`) to match it literally.

Octal and Hexadecimal -- \o, \x

Use `\x` and `\o` in an expression to find a comma (hex `2C`) followed by a space (octal `40`) followed by the character `2`:

• ```numstr = 'Easy as 1, 2, 3';

[mat idx] = regexp(numstr, '\x2C\o{40}2', 'match', 'start')
mat =
', 2'
idx =
10
```

Special Characters -- \char

Use `\` before a character that has a special meaning to the regular expression functions if you want that character to be interpreted literally. The intention in this example is to have the string '(ab[XY|Z]c)' interpreted literally. The first expression does not do that because `regexp` interprets the parentheses and | sign as the special characters for grouping and logical OR:

• ```regexp('(ab[XY|Z]c)', '(ab[XY|Z]c)', 'match')
ans =
'ab[XY'    'Z]c'
```

This next expression uses a \ before any special characters. As a result the entire string is matched:

• ```
regexp('(ab[XY|Z]c)', '\(ab\[XY\|Z\]c\)', 'match')
ans =
'(ab[XY|Z]c)'
```

 Character Classes Logical Operators