略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: mb_regex_set_options

2024-04-24

mb_regex_set_options

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mb_regex_set_optionsSet/Get the default options for mbregex functions

说明

mb_regex_set_options(?string $options = null): string

Sets the default options described by options for multibyte regex functions.

参数

options

The options to set. This is a string where each character is an option. To set a mode, the mode character must be the last one set, however there can only be set one mode but multiple options.

Regex options
Option Meaning
i Ambiguity match on
x Enables extended pattern form
m '.' matches with newlines
s '^' -> '\A', '$' -> '\Z'
p Same as both the m and s options
l Finds longest matches
n Ignores empty matches
e eval() resulting code
Regex syntax modes
Mode Meaning
j Java (Sun java.util.regex)
u GNU regex
g grep
c Emacs
r Ruby
z Perl
b POSIX Basic regex
d POSIX Extended regex

返回值

The previous options. If options is omitted or null, it returns the string that describes the current options.

更新日志

版本 说明
8.0.0 If the parameter options is given and not null, the previous options are returned. Formerly, the current options have been returned.
8.0.0 options is nullable now.

参见

  • mb_split() - 使用正则表达式分割多字节字符串
  • mb_ereg() - Regular expression match with multibyte support
  • mb_eregi() - Regular expression match ignoring case with multibyte support
add a noteadd a note

User Contributed Notes 2 notes

up
1
indeyets at php dot net
12 years ago
It's a bit trickier, than patryk wrote:

There are parameters (you can specify several of these at the same time):

'i': ONIG_OPTION_IGNORECASE;
'x': ONIG_OPTION_EXTEND;
'm': ONIG_OPTION_MULTILINE;
's': ONIG_OPTION_SINGLELINE;
'p': ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE;
'l': ONIG_OPTION_FIND_LONGEST;
'n': ONIG_OPTION_FIND_NOT_EMPTY;
'e': eval() resulting code

And there are "modes" (if you specify several of these, the LAST one will be used):
'j': ONIG_SYNTAX_JAVA;
'u': ONIG_SYNTAX_GNU_REGEX;
'g': ONIG_SYNTAX_GREP;
'c': ONIG_SYNTAX_EMACS;
'r': ONIG_SYNTAX_RUBY;
'z': ONIG_SYNTAX_PERL;
'b': ONIG_SYNTAX_POSIX_BASIC;
'd': ONIG_SYNTAX_POSIX_EXTENDED;

You can find descriptions of these constants here: http://www.geocities.jp/kosako3/oniguruma/doc/API.txt
up
0
patryk dot szczyglowski at gmail dot com
13 years ago
Supported options are:

i - ONIG_OPTION_IGNORECASE
x - ONIG_OPTION_EXTEND
m - ONIG_OPTION_MULTILINE
s - ONIG_OPTION_SINGLELINE
p - ONIG_OPTION_MULTILINE | ONIG_OPTION_SINGLELINE
l - ONIG_OPTION_FIND_LONGEST
n - ONIG_OPTION_FIND_NOT_EMPTY
j - ONIG_SYNTAX_JAVA
u - ONIG_SYNTAX_GNU_REGEX
g - ONIG_SYNTAX_GREP
c - ONIG_SYNTAX_EMACS
r - ONIG_SYNTAX_RUBY
z - ONIG_SYNTAX_PERL
b - ONIG_SYNTAX_POSIX_BASIC
d - ONIG_SYNTAX_POSIX_EXTENDED
e - eval() resulting code

Constants above are from Oniguruma regexp library, which is used internally. Default value for PHP 5.2.x is 'pr'.

官方地址:https://www.php.net/manual/en/function.mb-regex-set-options.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3