Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Lua regex (string function)     - Linux system ARP attack solution (Linux)

- SQL MySQL query table duplicate data (Database)

- CentOS7 management of systemd (Linux)

- How to install MySQL on Linux Dock (Database)

- MySQL 5.7 perfectly distributed transaction support (Database)

- Use Python automatically cleared Android Engineering excess resources (Programming)

- The OpenGL ES GLFW window structures (Programming)

- C ++: Postmodern systems programming language (Programming)

- Sniffer Linux Environment (Linux)

- A summary of Java multi-threaded programming - acquaintance multithreading (Programming)

- On Android running ClojureScript (Linux)

- iscsiadm command usage (Linux)

- Ubuntu install Oracle 10g process and problem solution (Linux)

- An Example of GoldenGate Extract Process Hang Problem Solving (Database)

- OpenSSL: implementation creates a private CA, certificate signing request Explanation (Server)

- To set up the printer use Nagios Monitoring Server (Server)

- Installation image conversion tool on your Ubuntu Converseen 0.8.1 (Linux)

- MySQL tmpdir parameter modification (Database)

- cat command uses the Linux redirection merge files (Linux)

- VirtualBox virtual machine to install Linux (Linux)

  Lua regex (string function)
  Add Date : 2018-11-21      
  The following table lists all character classes Lua support:
 . Arbitrary character
% A letter
% C control character
% D digital
% L lowercase letters
% P punctuation characters
% S whitespace
% U uppercase
% W letters and numbers
% X hexadecimal digits

% Z represents 0 characters

There are some special characters in pattern matching

()% + -.? * [^ $

% Used special characters escape character, '%' character match point '.', '%%' Matches the character '%'.

Escape character '%' can not only be used to escape special characters can also be used for all non-alphanumeric characters. When a character in doubt, for safety reasons, please use the escape character escaped him.

+ Matches the preceding character one or more times
* Matches the preceding character zero or more times
- Matches the preceding character zero or more times
? Match the previous character 0 or 1 times


(1) replace the non-alphabetic string into a digital '.'

print (string.gsub ( "Hello, up-down!", "% A", "."))
    -.> Hello..up.down 4

(Number 4 is not part of the string result, he is the second result gsub return, representing the number of alternative occurrence. Other results on printing gsub example will ignore this value)

(2) '% d +' matches one or more digits (integer):

i, j = string.find ( "the number 1298 is even", "% d +")
    -> Print (i, j) -> 12 15

(3) to match the date format

s = "Today is 30/05/1999, firm"

print (string.sub (s, string.find (s, ""% d% d /% d% d /% d% d% d% d "")) -> 30/05/1999

(4) intercept the desired file name (the middle part of the file name may be jpg | png | jpeg | gif)

local str1 = "wKgAgk1_M36eGCazAAHAC_MLulA790.jpg_200x200_2.jpg"
local str2 = "wKgAgk1_M36eGCazAAHAC_MLulA790.png_200x200_2.jpg"

_, Index1 = string.find (str1, "%.% A% a% a_")
_, Index2 = string.find (str2, "%.% A% a% a_")
print (string.sub (str1,1, index1-1))

-> WKgAgk1_M36eGCazAAHAC_MLulA790.jpg (the match is .jpg_ or .png_)
print (string.sub (str2,1, index2-1))

-> WKgAgk1_M36eGCazAAHAC_MLulA790.png (the match is .jpg_ or .png_)
print (string.gsub (str2, "_% d + x% d + _% d%.% a +", ""))

 -> WKgAgk1_M36eGCazAAHAC_MLulA790.png (matching the _200x200_2.jpg)

Other extensions:

print ( "===================" ..os.date () .. "================= ====== ")

- View CPU time:

local x3 = os.clock ()
local s = 0
for i = 1, 100000 do
path, _ = string.gsub (str2, "_% d + x% d + _% d%.% a +", "")
local x4 = os.clock ()
print (string.format ( "Processed:% .2f \ n", x4 - x3))
- Android Dynamic efficiency articles: a brilliant Loading Analysis and Implementation (Programming)
- Security: set limits on password (Linux)
- On the PC goes heavy security watch your startup items (Linux)
- Detailed LVM2 (Linux)
- Setting Wetty do not need an account login command line operations (Linux)
- Linux command line under HTTP traffic sniffing tool: httpry (Linux)
- Related to optimize the use of Btrfs file system on SSD (Linux)
- Build your own Python coding environment (Linux)
- Use install_updates upgrade GAMIT / GLOBK (Linux)
- HomeKit User Interface Guidelines (Linux)
- Use the command line MySQL database backup and recovery (Database)
- 14.04.3 Ubuntu configuration and successfully compiled source code Android 6.0 r1 (Programming)
- You really do need to know a variety of programming languages (Programming)
- Java Prototype Pattern (Programming)
- Give your photos Instagram style filters plus program in ubuntu (Linux)
- Ubuntu method for single-card dual-IP (Linux)
- Linux signal and orphans, and zombie process (Programming)
- How to use the TF / SD card making Exynos 4412 u-boot boot disk in Mac (Linux)
- Bootstrap 3.3.5 release download, Web front-end UI framework (Linux)
- IronPython and C # to interact (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.