Let's talk about regular expressions and show some examples of regular expression implementations.

Regular expressions are a concise and flexible way to identify certain strings. To validate data entry or do search and information extraction in texts.
Normal sequences used on license plates Portuguese system, according to wikipedia, are: AA-00-00 or 00-AA-00 or 00-00-AA

To identify these patterns using regular expressions we can use the following:

AA-00-00

[A-Z] {2} - [0-9]} {2 - [0-9] {2}

00-AA-00

[0-9] {2} - [A-Z] {2} - [0-9] {2}

00-00-AA

[0-9] {2} - [0-9] {2} - [A-Z] {2}

Another practical example is to find three distinct sequences, as a real number, a real number with percentage a number in scientific notation.

Thus to identify a real number and counting as valid numbers with leading zeros and numbers only zeros to the right of the decimal point such as 002.0 or even 0.0 is used the following regular expression:

- [0-9] + [0-9] +

To identify a real number with percentage just add the sign '%':

- [0-9] + [0-9] +%

And, considering that for scientific notation can be represented with an 'e' case-sensitive and is always raised to a positive or negative integer is:

- [0-9] + [0-9] + [ee] - [0-9] +

Another example currently very useful, is to use regular expressions to validate email addresses.
To validate emails will consider the following rules:

- You must start with an alphanumeric character

- Before @ alphanumeric and can have the following three symbols (-. _)

- After the @ equal but is mandatory to have a point

- After this point can have 2, 3 or 4 letters.

[A-Za-z0-9] + ([A-Za-z0-9 _.-]) * [@] [A-Za-z0-9] + ([A-Za-z0-9 _.-]) * [.] [A-Za-z] {2,4}

___

MM

- Read more about Regular Expressions
- Log in to post comments