PHP Terms Regular Expressions POSIX

 

- Info:

- POSIX stands for Portable Operating System Interface for Unix.

- POSIX is regular expression syntax.

- POSIX is attempt to standardize how regular expressions are implemented in different programming languages.

 

- Understanding Regular Expressions:

- Most important thing to understand about regular expressions is dual meaning of the symbols depending on the context.

For instance symbol [a-z] has two completely different meanings.

- As a PART of regular expression [a-z] represents any single character from a-z.

As a COMPLETE regular expression symbol [a-z] means: find any of the letters from a-z anywhere in a string.

As a COMPLETE regular expression symbol ^[a-z] means: find any of the letters from a-z at the begining of string.

- Regular expressions are ALWAYS used in combinations with a functions which either search or replace patterns.

Search functions search for a pattern in a string returning TRUE or FALSE.

Replace functions first search for a pattern and then replace found characters with replacement string

 

    

EXAMPLE

DESCRIPTION

 

p.p

Matches any string containing p, followed by any character, in turn followed by another p.

 

^.{2}$

Matches any string containing exactly two characters.

 

<b>(.*)</b>

Matches any string enclosed within <b> and </b>.

 

p(hp)*

Matches any string containing p followed by zero or more instances of the sequence hp.