国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP源碼 正則表達(dá)式二

正則表達(dá)式二

Jun 08, 2016 pm 05:30 PM
nbsp pattern quot string

<script>ec(2);</script>

5."[]"方括號(字符簇)用法
? ? 1)[]匹配一個字符,在[]中使用^開頭表示取非,即其后的字符全部是不匹配的。
? ? 例1:[a-zA-Z0-9]匹配所有大小寫字母和數(shù)字。
? ? 例2:[\n\t\r\f]匹配所有空字符。
? ? 例3:[^A-Z]不匹配大寫字母。
? ? 例4:^[^0-9]匹配不以數(shù)字開頭的字符或字符串
? ? 2)特殊字符"."(句點(diǎn))匹配除了"新行"之外的所有字符,模式^.abc$匹配任何以abc結(jié)尾的字符,但是不能匹配其本身。模式"."則可以匹配任何字符串,除了空字符串和只有一個"新行"字符的字符串。
? ? 例1:'^.abc$';匹配所有尾部含有abc的字符串,不匹配小數(shù)(新行),當(dāng)不匹配abc。
? ? 例2:'.';匹配所有字符串,但不匹配空值。
? ? 例3:'.abc';匹配所有含abc的字符串,小數(shù)等等都可以,前提是不以abc為首,不匹配abc。
? ? 例4:'.abc$';匹配所有以abc結(jié)尾的字符串,任何小數(shù)等等都可以,不匹配abc。
? ? 3)php提供了內(nèi)置通用字符簇:
? ? [[:alpha:]]任何字母
? ? [[:digit:]]任何數(shù)字
? ? [[:alnum:]]任何字母和數(shù)字
? ? [[:space:]]任何空白字符
? ? [[:upper:]]任何大寫字母
? ? [[:lower:]]任何小寫字母
? ? [[:punct:]]任何表點(diǎn)符號
? ? [[:xdigit:]]任何十六進(jìn)制數(shù)字
? ? [[:cntrl:]]任何ASCII值小于32的字符
? ? 注意:以上字符簇有個特點(diǎn),只要被匹配的字符或字符串中有此字符,即匹配正確,不管字符串是以什么方式組成的。
6."{}"大括號用法
? ? 1)方括號只能匹配一個字符,而匹配多個字符只能用{}實(shí)現(xiàn):{}用來確定前面內(nèi)容出現(xiàn)的次數(shù)。{n}表示出現(xiàn)n次;{m,n}表示出現(xiàn)m~n次,包括m和n次;{n,}表示出現(xiàn)n次或者n次以上。
? ? 例1:^a{10}$;匹配aaaaaaaaaa。
? ? 例2:[0-9]{1,}$;匹配所有>0的數(shù)。
? ? 2)"{}"與通配符之間的關(guān)系
? ? ???相當(dāng)于 {0,1} 零次或一次
? ? *??..... {0,} 零次或無數(shù)次
? ? +??..... {1,} 一次或無數(shù)次
7."()"用法
? ? 圓括號"()"括住的pattern表示子模式,如$pattern='([1-9]{1}[0-9]{3})-([0-1]{1}[1-2]{1})-([0-3]{1}([0-9]|))';()擴(kuò)住的就是一個個子模式,()相當(dāng)于把他們獨(dú)立起來,分別匹配而相互不干擾。
二.POSIX風(fēng)格正則表達(dá)式函數(shù)
1.ereg
? ? ereg(pattern,string,[array $regs]);
? ? eregi(pattern,string,[array $regs]);
? ? ereg函數(shù)在string中找到滿足pattern模式的文本,如果找到true,沒找到false。如果有第三個參數(shù)$regs,那找到的文本將放在$regs[0]中,并且regs數(shù)組中將一次存放各個圓括號表達(dá)的子模式匹配的結(jié)果。$regs[1]中存放了第一個子模式所匹配的結(jié)果,$regs[2]中是第二個,順序從左到右,依次類推。如果沒有找到匹配的文本,$regs數(shù)組的值不會被改變。
? ? 注意:如果找到了匹配的文本,不管找到的子模式是多少個>9還是 ? ? eregi()函數(shù)與ereg()基本用法相同,只是eregi對大小寫不敏感。
2.ereg_replace和eregi_replace
? ? ereg_replace(pattern,string replacement,string)
? ? eregi_replace(pattern,string replacement,string)
? ? string字串中滿足pattern的文本將被替換成replacement。如果string中有pattern匹配的文本,那么返回替換之后的值,如果沒有,則返回原來的string值。
? ? 如果pattern中包含子模式,子模式可以有選擇的被保留而不被替換。
? ? 例1:pattern中的第二個子模式不被替換,replacement可寫成這樣:replacement\\2。這樣string中匹配的pattern的字符串將被替換為replacement+pattern2,pattern2表示匹配pattern的文本中又匹配pattern的第二個子模式的文本。如果使用"\\0"表示保留整個匹配文本。利用這個特性可以實(shí)現(xiàn)在特定的字符串之后插入文本的操作。
? ? replacement必須是字符串類型變量,如果不是,替換時將強(qiáng)制轉(zhuǎn)換成字符串類型。
3.split()函數(shù)和spliti()函數(shù)用法
? ? split(pattern,string,[int limit]);
? ? spliti(pattern,string,[int limit]);
? ? split以正則表達(dá)式pattern定義的模式為分隔符將string分隔成幾個部分。如果分隔成功,返回的值為各個分隔后部分組成的數(shù)組,失敗則返回false??蛇xlimit表示最大分割塊數(shù)。如果limit為5,那么即使string有>5個的地方符合pattern,string也只被分割為5個部分,最后一個部分是string去掉前四個部分后剩下的部分。返回值中也只有5個元素。
三.perl風(fēng)格正則表達(dá)式及相關(guān)函數(shù)
1.perl正則語法
? ? perl分隔符,可使用"/","!"和"{}"。
? ? 例1:/^[^0-9]/? ???!^[0-9]!? ? {^[0-9]}三個都一樣。
? ? 在分隔符內(nèi)部,分隔字符本身就是一個特殊敏感字符,要進(jìn)行轉(zhuǎn)義。如果用分隔符"/",正則中又用了表達(dá)字符的"/",則必須要用"\/"。如果混合用"/"和"!"就沒問題。
? ? 例2:/\/\/$/? ? !//$! 兩者也相同
? ? 例3:!^\!\![0-9]$!? ? /^!![0-9]$/ 兩者也相同
2.perl特殊意義字符
? ? \a ASCII值為7的告警符
? ? \b 詞的邊界
? ? \A 和脫出符號("/")等價
? ? \B 非詞邊界
? ? \cn 控制字符
? ? \d 單個數(shù)字
? ? \D 單個非數(shù)字
? ? \s 單個空白
? ? \S 單個非空白
? ? \w 單個的字母或下劃線
? ? \W 單個的非詞字符(不是字母也不是下劃線)
? ? \Z 從目標(biāo)字串的尾部開始匹配
3.高級特性
? ? 1)或運(yùn)算"|":
? ?? ???例如!^ex|em!匹配條件是ex或em開頭的字符串,還可以寫成!^e(x|m)!。
? ? ? ? 注意:()內(nèi)的內(nèi)容代表子模式\
? ? 2)邏輯符號后面的模式選項(xiàng)
? ?? ???!正則表達(dá)式!邏輯選項(xiàng)
? ? ? ? A:只匹配位于目標(biāo)字串開頭的字符。
? ? ? ? E:該選項(xiàng)使轉(zhuǎn)義字符$構(gòu)成的正則表達(dá)式只匹配目標(biāo)字符串的結(jié)尾字符。如果選擇m選項(xiàng),該選項(xiàng)就被忽略。
? ? ? ? U:該選項(xiàng)禁止最大長度的搜索。一般情況下,搜索會盡量找最長的匹配字符串。例如模式/a+/在"caaaaab"字符串中的匹配結(jié)果是"aaaaa",但是使用該選項(xiàng)的模式/a+/U匹配的結(jié)果會是"a"。
? ? ? ? S:對模式進(jìn)行學(xué)習(xí),提高查找速度。
? ? ? ? i:該選項(xiàng)忽略大小寫。
? ? ? ? m:該選項(xiàng)將含有換行符的字符串視為多行而不是一行。這個時候"$","^"等字符會匹配每個換行符。
? ? ? ? s:該選項(xiàng)使句點(diǎn)"."也匹配換行符。
? ? ? ? x:該選項(xiàng)通知PHP解釋器在分析的時候忽略正則表達(dá)式定義中的非轉(zhuǎn)義空格符。這樣可以在正則表達(dá)式中使用空格來增強(qiáng)其可讀性,但這時在表達(dá)式中使用空格符必須使用轉(zhuǎn)義字符。
? ? 3)擴(kuò)展模式符號。
? ?? ???(?#comment)? ? 添加注釋comment,可以增強(qiáng)正則可讀性。
? ? ? ? (?=pattern)? ? 指定在模式之后必須跟隨值pattern。
? ? ? ? (?!pattern)? ? 指定在模式之后不能跟隨值pattern。
? ? ? ? (?n)? ?? ?? ???在模式內(nèi)部而非結(jié)尾處定義模式選項(xiàng)n。
? ? ? ? (?: )? ?? ?? ???消耗字符,不捕獲匹配結(jié)果。
? ? ? ? 例:echo ereg("?:^a$","a");//無任何輸出

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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

How to Fix Activation Error Code 0xc004f069 in Windows Server How to Fix Activation Error Code 0xc004f069 in Windows Server Jul 22, 2023 am 09:49 AM

The activation process on Windows sometimes takes a sudden turn to display an error message containing this error code 0xc004f069. Although the activation process is online, some older systems running Windows Server may experience this issue. Go through these initial checks, and if they don't help you activate your system, jump to the main solution to resolve the issue. Workaround – close the error message and activation window. Then restart the computer. Retry the Windows activation process from scratch again. Fix 1 – Activate from Terminal Activate Windows Server Edition system from cmd terminal. Stage – 1 Check Windows Server Version You have to check which type of W you are using

See all articles