STDIO
Tìm kiếm gần đây
    Nội dung
    0
    0
    Chia sẻ
    Nội dung
    0
    0
    Chia sẻ

    Regular Expression Cheat Sheet

    A Regular Expression cheat sheet (Regex cheat sheet) help you quick approach Regex.
    30/06/2021 1 phút đọc
    Regular Expression Cheat Sheet

    Characters

    \d 1 digit from 0 to 9
    \D 1 character that is not digit
    \w Letter, digit or underscore
    \W Not letter, digit or underscore
    \s Space, \t, \r, \n
    \S Not space, \t, \r, \n
    . Any characters except line break

    Quantifiers

    ? None or once times
    * Zero or more times
    + Once or more times
    {n, m} n times to m times
    {n, } n times to more times
    {n} Exactly n times
    \d{2,6} matches 358 in ID is 358

    Character classes

    [...] One of characters
    [x-y] One of characters in range from x to y
    [^x] One of charactes that is not x
    [^x-y] One of characters that is not in range from x to y
    [\d\D] One of characters that is digit or not digit
    [AOK] matches A, K in ATTACK
    [a-zA-Z] matches a to z, A to Z in text
    [3-9] matches 5, 6 in 562 dollars

    Special characters

    \n New line
    \r Carriage return
    \t Tab
    \OCTAL Octal character OCTAL
    \xHEX Hexadecimal character HEX
    \xA9S matches ©S in ©STDIO Training

    Anchors

    ^ Start of string or start of line in multiline pattern
    \A Start of string
    $ End of string or end of line in multiline pattern
    \Z End of string
    \b Word boundary
    \B Not word boundary
    .*php$ matches account.php in file path .../account.php but does not match .../account.php.html
    \bcoin matches coin in 12 coins but does not match coin in bitcoin

    Groups & Logic

    xx|yy xx or yy
    (...) Capturing group
    (?:...) Non-capturing group
    \digits Content of group \1, \2, \3...
    http:|ftp: matches ftp: in ftp://localhost or http: in http://localhost

    Lookarrounds

    (?=...) Lookahead
    (?!...) Negative lookahead
    (?<=...) Lookbehind
    (?<!...) Negative lookbehind
    (?<!http:)\/\/ matches // that has no https: before in https://training.stdio.vn

    Modifiers

    g Global match
    i Case-insensitive
    m Multiple lines
    s Treat string as single line
    u Treat pattern as Unicode

    Meta-characters

    (?<!https:)\/\/ matches // that has no https: before in https://localhost//training
    Using escape character \ in common

     

    *Regular Expression Engine (REE) process Regular Expression. Different REEs are not fully compatible with each other.

    0 Bình luận
    STDIO Training

    STDIO Training

    Trung tâm đào tạo lập trình cho doanh nghiệp

    Khi bạn nhấn vào sản phẩm do chúng tôi đề xuất và mua hàng, chúng tôi sẽ nhận được hoa hồng. Điều này hỗ trợ chúng tôi có thêm kinh phí tạo nhiều nội dung hữu ích. Tìm hiểu thêm.
    STDIO

    Trang chính

    Công ty TNHH STDIO

    • 30, Trịnh Đình Thảo, Hòa Thạnh, Tân Phú, Hồ Chí Minh
      +84 28.36205514 - +84 942.111912
      developer@stdio.vn
    • 383/1 Quang Trung, Phường 10, Quận Gò Vấp, Hồ Chí Minh
      Số giấy phép ĐKKD: 0311563559 do sở Kế hoạch và Đầu Tư TPHCM cấp ngày 23/02/2012
    ©STDIO, 2013 - 2021