# Meta characters: \b, \w, \s

Inaport regular expressions recognise a number of meta characters, which are used simplify some expressions. These include:

\b - matches a word boundary

\w - matches any word character (defined as alphanumeric character and the underscore character)

\s - matches any space character (blank, tab, new line)

Some examples might make this clearer.

The pattern "red" matches the word red. But it also matches "red" in "shred", "bred", or "irredeemable", which is probably not what we want.

- The next step might be to try putting spaces around the word: " red ". This will knock the matches above, but it will not match red at the beginning or end of a line, or if there is a tab character instead of a space.
- The pattern "\sred\s" takes care of these problems, because the "\s" will match space, tab or a line break. However, it too will fail to match "red;" or "red."
- The best pattern is "\bred\b". "\b" matches any word boundary i.e. any transition from a word character (alphanumeric or underscore) to a non-word character (space, line break, punctuation).

"\w" is useful for finding words in strings. The most common pattern to use is "\w+", which matches one or more word characters. It will therefore match "red", "bread", "fed" etc. Suppose an input field contains names such as "John Smith" and "Fred Jones".

- A pattern "^\w+" will match the first word: "John" or "Fred".
- A pattern "\w+$ will match the last word: "Smith" or "Jones".
- The function replace(#1, "(\w+)\s(\w+)", "$2, $1") will transform the names to: "Smith, John" and "Jones, Fred" (see Groups and replace() for further information on how this was done)