正則表達式(二)

反向引用:對模式單元捕獲的文本內容引用php

UTF8編碼下漢字Unicode編碼範圍: \u4e00-\u9fa5正則表達式

捕獲的文本儲存在臨時緩衝區中,緩衝區編號範圍爲1-99,數組

反向引用格式爲 \編號(例如\1)函數

非捕獲元字符 "?:" (忽略捕獲的這個元字符,緩衝區編號順移)編碼

經常使用函數
preg_match int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] ) 搜索subjectpattern給定的正則表達式的一個匹配.
preg_match_all int preg_match_all ( string $pattern , string $subject [, array &$matches [, int $flags = PREG_PATTERN_ORDER [, int $offset = 0 ]]] ) 搜索subject中全部匹配pattern給定正則表達式 的匹配結果而且將它們以flag指定順序輸出到matches中.
preg_replace mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) 搜索subject中匹配pattern的部分, 以replacement進行替換。
preg_repalce_callback mixed preg_replace_callback ( mixed $pattern , callable $callback , mixed $subject [, int $limit = -1 [, int &$count ]] ) 這個函數的行爲除了 能夠指定一個 callback 替代 replacement 進行替換 字符串的計算,其餘方面等同於 preg_replace()
preg_filter mixed preg_filter ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) preg_filter()等價於preg_replace() 除了它僅僅返回(可能通過轉化)與目標匹配的結果.
preg_grep array preg_grep ( string $pattern , array $input [, int $flags = 0 ] ) 返回給定數組input中與模式pattern 匹配的元素組成的數組.
preg_split array preg_split ( string $pattern , string $subject [, int $limit = -1 [, int $flags = 0 ]] ) 經過一個正則表達式分隔給定字符串.
preg_quote string preg_quote ( string $str [, string $delimiter = NULL ] ) preg_quote()須要參數 str 並向其中 每一個正則表達式語法中的字符前增長一個反斜線。 這一般用於你有一些運行時字符串 須要做爲正則表達式進行匹配的時候。
相關文章
相關標籤/搜索