|Perl Regular Expressions|
|Written by Philip L Yuson|
Who is this for
This article is for those who want to become familiar with regular expressions.
Who is this for?
Pre-requisite skills you need
Check the string "Concept Solutions Corporation" and see if it has the string "on" in it.
Unless the language has a pattern matching function, you have to write a pattern matching function yourself. You will have to get the length of the string, go through the string one byte at a time and match the string "on" against each byte. If you want to take the last string that matched, you need a routine to 'remember' that it has found a first match. To make our life easier, we'll just assume that we want to see if the string has the pattern "on".
You can write a routine to do this:
Note that this is just a simple compare. If you want to return the string before the pattern, you will need to add more code.
This whole routine can be written this way:
Metacharacters are used to define the pattern. Qualifiers are used to limit the number of times the pattern is searched. So in our example pattern "on", the metacharacters are o and n - fairly straightforward. In our next article, we will discuss about using other metacharacters to create more complicated patterns.