عبارت منظم یا regular experssion چیزی بیشتر از یک جمله متشکل از کاراکتر ها نیست !
این جمله اساس کاربرد الگوی ماشینی را فراهم می کند .
با استفاده عبارات منظم میتوانید در بین عبارات جستجو کنید ، میتوانید یک عبارات را در یک رشته جایگذاری کنید ، همچنین می توانید یک عبارات را از قسمت های زیادی جدا کنید
زبان php دو سری از توابع "عبارات منظم" را پیشنهاد میدهد . هر کدام از آنها برای گونه خاصی از عبارت منظم است ، شما می توانید بر اساس نیازتان از هر کدام از آنها استفاده کنید .
- Posfix Regular Experssions
- PERL style regular experssions
Brackets
Sr.No | Expression & Description |
---|---|
1 |
[0-9] It matches any decimal digit from 0 through 9. |
2 |
[a-z] It matches any character from lower-case a through lowercase z. |
3 |
[A-Z] It matches any character from uppercase A through uppercase Z. |
4 |
[a-Z] It matches any character from lowercase a through uppercase Z |
Quantifiers
Sr.No | Expression & Description |
---|---|
1 |
p+ It matches any string containing at least one p. |
2 |
p* It matches any string containing zero or more p's. |
3 |
p? It matches any string containing zero or more p's. This is just an alternative way to use p*. |
4 |
p{N} It matches any string containing a sequence of N p's |
5 |
p{2,3} It matches any string containing a sequence of two or three p's. |
6 |
p{2, } It matches any string containing a sequence of at least two p's. |
7 |
p$ It matches any string with p at the end of it. |
8 |
^p It matches any string with p at the beginning of it. |
Examples
Sr.No | Expression & Description |
---|---|
1 |
[^a-zA-Z] It matches any string not containing any of the characters ranging from a through z and A through Z. |
2 |
p.p It matches any string containing p, followed by any character, in turn followed by another p. |
3 |
^.{2}$ It matches any string containing exactly two characters. |
4 |
<b>(.*)</b> It matches any string enclosed within <b> and </b>. |
5 |
p(hp)* It matches any string containing a p followed by zero or more instances of the sequence php. |
Predefined Character Ranges
Sr.No | Expression & Description |
---|---|
1 |
[[:alpha:]] It matches any string containing alphabetic characters aA through zZ. |
2 |
[[:digit:]] It matches any string containing numerical digits 0 through 9. |
3 |
[[:alnum:]] It matches any string containing alphanumeric characters aA through zZ and 0 through 9. |
4 |
[[:space:]] It matches any string containing a space. |
Sr.No | Function & Description |
---|---|
1 |
ereg() The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise. |
2 |
ereg_replace() The ereg_replace() function searches for string specified by pattern and replaces pattern with replacement if found. |
3 |
eregi() The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive. |
4 |
eregi_replace() The eregi_replace() function operates exactly like ereg_replace(), except that the search for pattern in string is not case sensitive. |
5 |
split() The split() function will divide a string into various elements, the boundaries of each element based on the occurrence of pattern in string. |
6 |
spliti() The spliti() function operates exactly in the same manner as its sibling split(), except that it is not case sensitive. |
7 |
sql_regcase() The sql_regcase() function can be thought of as a utility function, converting each character in the input parameter string into a bracketed expression containing two characters. |