14 compilers, dictionaries, DNA-data and so on. When looking for |
14 compilers, dictionaries, DNA-data and so on. When looking for |
15 a particular string in a large text we can use the |
15 a particular string in a large text we can use the |
16 Knuth-Morris-Pratt algorithm, which is currently the most |
16 Knuth-Morris-Pratt algorithm, which is currently the most |
17 efficient general string search algorithm. But often we do |
17 efficient general string search algorithm. But often we do |
18 \emph{not} just look for a particular string, but for string |
18 \emph{not} just look for a particular string, but for string |
19 patterns. For example in programming code we need to identify |
19 patterns. For example in program code we need to identify |
20 what are the keywords, what are the identifiers etc. A pattern |
20 what are the keywords, what are the identifiers etc. A pattern |
21 for identifiers could be stated as: they start with a letter, |
21 for identifiers could be stated as: they start with a letter, |
22 followed by zero or more letters, numbers and underscores. |
22 followed by zero or more letters, numbers and underscores. |
23 Also often we face the problem that we are given a string (for |
23 Also often we face the problem that we are given a string (for |
24 example some user input) and want to know whether it matches a |
24 example some user input) and want to know whether it matches a |
67 \begin{lstlisting}[language={},numbers=none,keywordstyle=\color{black}] |
67 \begin{lstlisting}[language={},numbers=none,keywordstyle=\color{black}] |
68 user@localserver |
68 user@localserver |
69 disposable.style.email.with+symbol@example.com |
69 disposable.style.email.with+symbol@example.com |
70 \end{lstlisting} |
70 \end{lstlisting} |
71 |
71 |
72 As mentioned above, identifiers, or variables, in program text are often required |
72 As mentioned above, identifiers, or variables, in program code |
73 to satisfy the constraints that they start with a letter and |
73 are often required to satisfy the constraints that they start |
74 then can be followed by zero or more letters or numbers and |
74 with a letter and then can be followed by zero or more letters |
75 also can include underscores, but not as the first character. |
75 or numbers and also can include underscores, but not as the |
76 Such identifiers can be recognised with the regular expression |
76 first character. Such identifiers can be recognised with the |
|
77 regular expression |
77 |
78 |
78 \begin{center} |
79 \begin{center} |
79 \pcode{[a-zA-Z] [a-zA-Z0-9_]*} |
80 \pcode{[a-zA-Z] [a-zA-Z0-9_]*} |
80 \end{center} |
81 \end{center} |
81 |
82 |