Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR LUA

lua patterns

-- Lua Patterns is Lua's very own version of Regex
-- The Regex library is much bigger than Lua itself, so Lua Patterns was
-- implemented to still allow developers to automate string searching

-- These are to find directories and files that are emitted by
-- the Windows `dir .` command
local FileP = "%d+%s[%a%.%d_-]+
" -- NOTE This will still include the number next to the filename which represents how big the file is in bytes
local DirP = "<DIR>%s+[%a%.%d_-]+
" -- NOTE This will still include <DIR>

-- Lua Patterns is similar to Regex in alot of ways, %a represents
-- all letters and %A everything BUT letters.
-- [] represents a group of things to search for and [^] represents
-- a group of things to NOT search for.
-- * represents 0 or more matches, + represents 1 or more matches.

-- Searches for a single Pattern match in Text and replaces it with
-- ReplaceText and returns a new string
function SearchAndReplace(Text,Pattern,ReplaceText)
	return string.gsub(Text,Pattern,ReplaceText,1)
end

 
PREVIOUS NEXT
Tagged: #lua #patterns
ADD COMMENT
Topic
Name
3+5 =