Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Regular expressions in Lua

Shulou Source: shulou.com Published: 2022-06-02 19:09:00 11月14日 Update

Pattern

You can also use character classes in pattern strings. A character class refers to a pattern item that can match any character in a particular character collection. For example, the character class% d matches any number. So you can search for a date in dd/mm/yyyy format using the pattern string'% d% d _ Rank% d% d':

S = "Deadline is 30 Compact 05Compact 1999, firm"

Date = "% d%d/%d%d/%d%d%d%d"

Print (string.sub (s, string.find (s, date)-- > 30 Universe 05 Universe 1999

The following table lists all the character classes supported by Lua:

. Arbitrary character

% a letter

% c control character

% d number

L lowercase letters

% p punctuation character

% s blank character

% u capital letters

% w letters and numbers

% x hexadecimal number

Z represents the character of 0

Tags: Characters letters numbers patterns representatives hexadecimal uppercase uppercase lowercase date punctuation format white space face control search support regular expression Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL Shulou Tech Info Redmi Xiaomi