Home > Backend Development > PHP Tutorial > php regular expression

php regular expression

不言
Release: 2023-03-22 22:22:01
Original
1319 people have browsed it

This article introduces regular expressions in php, and I would like to share them with you. Friends who are interested can take a look at

  • The role of regular expressions
    Split, search, match, replace string


  • ##Separator


    • Forward slash (/)

    • hash symbol (#)

    • ##Negative symbol (~)

    Universal Atom

    • ##\d
    • Decimal 0 to 9

    • \D
    • Negate decimal numbers from 0 to 9

    • \w
    • Numbers and letters underline

    • \W
    • In addition to numbers and letters underline

    • \s
    • White space characters

    • \S
    • Except whitespace characters

##metacharacters

  • .
      Matches any single character except newline characters (\n, \r)
    • *
    • Matches the previous subexpression zero or more times
    • +
    • Matches the previous subexpression one or more times
    • ?
    • Matches the previous subexpression zero or one time
    • {n}
    • n is a non Negative integer, matches a certain number of n times
    • ##{n,}

      n is a non-negative integer, matches at least n times
    • {n,m}

      m and n are both non-negative integers, where n <= m. Match at least n times and match at most m times
    • ^

      Match the beginning of the input string
    • $

      Matches the end position of the input string
    • []

      represents matching an element in a set, such as [abc] represents matching a or b or c
    • ()

      Match the content within () and get
    • ##Pattern modifier


  • i

    Case-insensitive
    • m Treat the string as multiple lines, no matter which line it is, it can match

    • s Treat the string as a single line, and the newline character is treated as an ordinary character

    • e e Use with function preg_replace() (php7 to cancel)

    • U U Only match the most recent string, no repeated matches

    • x x Ignore whitespace in the pattern

    • A Force matching from the beginning of the target string

    • D If you use $ to limit the ending character, no newline at the end is allowed

    • u The pattern string is treated as UTF-8 (can be used to match Chinese)

    • To be continued……………………
Related recommendations:

Detailed explanation of JS regular expressions

Some commonly used Summary of regular expressions

Summary of regular expressions (practical summary)

The above is the detailed content of php regular expression. For more information, please follow other related articles on the PHP Chinese website!

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