Learn regular expressions in php, learn php regular expressions_PHP tutorial

WBOY
Release: 2016-07-13 10:20:49
Original
735 people have browsed it

Learn regular expressions in php, learn php regular expressions

Grammar format: is located in the delimiter "/" between.

1 The more commonly used metacharacters include: "+", "*", and "?".

Among them,

The "+" metacharacter stipulates that its leading character must appear one or more times in the target object,

The "*" metacharacter stipulates that its leading character must appear zero or consecutive times in the target object,

And the "?" metacharacter stipulates that its leading object must appear zero or once in the target object.

<span>1</span> /jim{2,6}/<span><</span><span>br</span><span>/></span>
<span>2</span> 上述正则表达式规定字符m可以在匹配对象中连续出现2-6次,因此,上述正则表达式可以同jimmy或jimmmmmy等字符串相匹配。<span><</span><span>br</span><span>/></span>
<span>3</span> 在对如何使用正则表达式有了初步了解之后,我们来看一下其它几个重要的元字符的使用方式。<span><</span><span>br</span><span>/></span>
<span>4</span> \s:用于匹配单个空格符,包括tab键和换行符;<span><</span><span>br</span><span>/></span>
<span>5</span> \S:用于匹配除单个空格符之外的所有字符;<span><</span><span>br</span><span>/></span>
<span>6</span> \d:用于匹配从0到9的数字;<span><</span><span>br</span><span>/></span>
<span>7</span> \w:用于匹配字母,数字或下划线字符;<span><</span><span>br</span><span>/></span>
<span>8</span> \W:用于匹配所有与\w不匹配的字符;<span><</span><span>br</span><span>/></span>
<span>9</span> . :用于匹配除换行符之外的所有字符。<span><</span><span>br</span><span>/></span>
Copy after login

Also:

Commonly used locators include: “^”, “$”, “b” and “B”.

The "^" locator specifies that the matching pattern must appear at the beginning of the target string,

The "$" locator specifies that the matching pattern must appear at the end of the target object,

The

b locator specifies that the matching pattern must appear at one of the two boundaries at the beginning or end of the target string,

The "B" locator stipulates that the matching object must be located within the two boundaries of the beginning and end of the target string, that is, the matching object cannot be used as the beginning or the target of the target string. The end of the string.

matches a specified range and is not limited to specific characters. For example:

/[A-Z]/
The above regular expression will match any uppercase letter from A to Z.
/[a-z]/
The above regular expression will match any lowercase letter in the range from a to z.
/[0-9]/
The above regular expression will match any number from 0 to 9.
/([a-z][A-Z][0-9])+/

What kind of regular expression should PHP learn?

The younger brother knelt down and asked. There are regular expressions in asp.net, regular expressions in js, and regular expressions in php (the ones in php seem to be regular expressions compatible with Perl). So these regular expressions seem to be somewhat the same. What I want to ask is whether "all" regular expressions have the same syntax? Or are there several regular expressions with different syntaxes? I am learning PHP now, what kind of regular expression should I learn? Do you need to learn regular expressions that are compatible with Perl? What kind of regular expression is Perl compatible? (I hope you can give me a good link to learn php regular expressions) Thank you very much! ! !

How to learn php regular expressions

There is actually no need to learn.
Let’s just start with a general look. Then wait and see when it is actually used. What regular expressions can do, string functions can basically do

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/864819.htmlTechArticleLearn regular expressions in php, learn php regular expression syntax format: located between the delimiter "/" between. 1 The more commonly used metacharacters include: +, *, and ?. Among them, + metacharacter rule...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template