Regular expressions are excellent for simpler parsing tasks, replaces, or splits. We will give a short introduction on them and show some examples. These will allow you to get better idea. At the end of this section, we will suggest further reading.
Usually, when you write a text as a pattern, this means that the text will be matched; for example, apple or pear
will match the highlighted parts from the following sentence: "Apple stores do not sell
apple or pear
.
"
These are case sensitive by default, so if the pattern were to be simply apple
, this will not match the first word of the sentence or the company name.
There are special characters that need to be escaped when you want to match them: .
, [
, ]
, (
, )
, {
, }
, -
, ^
, $
, \
(Well, some of these only in certain positions). To escape them, you should prefix them with \
, which will result in the following patterns: \., \[, \], \(, \), \{, \}, \-, \^, \$, \\.
When you do not want an exact match of characters, you...