# Regular expression quick start guide

### Quick Reference Table<br>

| Regular Expression Pattern    | Explanations                                                                                                                                                                                                                     | <p>Examples<br></p>                                                                                                    |             |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ----------- |
| <p>Meta characters  \[^$.     | ?\*+(<br></p>                                                                                                                                                                                                                    | <p>Special caracters used in regex.</p><ul><li>Must be escape with backslash "" to use a literal characters.</li></ul> | <p><br></p> |
| <p>Literal characters<br></p> | <p>All characters (except the metacharacters) match a single instance of themselves.<br></p><ul><li>{ and } are literal characters, unless they're part of a valid regular expression token (e.g. the {n} quantifier).</li></ul> | <p><em>/a/</em> matches "a"<br></p>                                                                                    |             |
| <p>\[characters]<br></p>      | <p>Character classes or character set. A character class matches a single character out of all the possibilities offered by the character class.<br></p>                                                                         | <p><em>/\[0-9]/</em> matches a single digit<br></p>                                                                    |             |
| <p>\[\d]<br></p>              | <p>Shorthand character classes matching digits. Same as \[0-9].<br></p>                                                                                                                                                          | <p><em>/\[\d]/</em> matches a single digit<br></p>                                                                     |             |
| <p>.<br></p>                  | <p>Dot matches any characters.<br></p>                                                                                                                                                                                           | <p><em>/a.c/</em> matches both "a4c" and "ayc"<br></p>                                                                 |             |
| ^                             | Matches at the start of the string the regex pattern is applied to. Matches a position rather than a character.                                                                                                                  | <p><br></p>                                                                                                            |             |
| $                             | Matches at the end of the string the regex pattern is applied to. Matches a position rather than a character.                                                                                                                    | <p><br></p>                                                                                                            |             |
| <p>{m,n}<br></p>              | <p>Matches at least “m” and at most “n” occurrences of preceeding character, character class or group.<br></p>                                                                                                                   | <p><br></p>                                                                                                            |             |
| \*                            | Matches zero or more occurrences of preceeding character, character class or group.                                                                                                                                              | <p><br></p>                                                                                                            |             |
| +                             | <p>Matches one or more occurrences of preceeding character, character class or group.<br></p>                                                                                                                                    | <p><br></p>                                                                                                            |             |
| ?                             | Matches zero or one occurrences of  preceeding character, character class or group.                                                                                                                                              | <p><br></p>                                                                                                            |             |
| ()                            | <p>Parentheses are used for group or capturing group<br></p>                                                                                                                                                                     | <p><br></p>                                                                                                            |             |
| \0, \1, \2, ...               | Substitute the value matched by the nth grouped sub-expression, used in remapped fields.                                                                                                                                         | <p><br></p>                                                                                                            |             |
| ?!                            | Not, as in "everything except this".                                                                                                                                                                                             | <p><br></p>                                                                                                            |             |

\
Examples<br>

Here are some examples:

Add 2720 prefix:

```
/^(\d+)$/2720\1/
```

or

```
/^([0-9]*)$/2720\1/
```

Strip first 4 digits:

```
/^([0-9]{4})([0-9]*)$/\2/
```

Strip # and 7 first digits:

```
/^([#])([0-9]{7})([0-9]*)$/\3/
```

### Web Online Tools

* Regular builder tool (with replace)  : [www.gskinner.com/RegExr](http://www.gskinner.com/RegExr)

Tips to use:

1. No need to enclose the Regular expression with '/'.
2. Replace : the regular expression must be split in two parts and '\\' replaced by '$'. For example, with '/^(\[0-9]\*)$/2720\1/', the '^(\[0-9]\*)$' would be filled on the first line and '2720$1' on the second line.

* Ruby regular expression editor and tester : [rubular.com](http://rubular.com/)<br>

### References

* [How to Use RegEx in Remapped Called and Calling Number Mask](https://docs.telcobridges.com/wiki/Toolpack:_How_to_Use_RegEx_in_Remapped_Called_and_Calling_Number_Mask)
