Questions tagged [lua-patterns]

Lua's native string pattern matching facility. Note that Lua patterns are not equivalent to a regex.

Lua's built-in string patterns employ syntax similar to POSIX- or Perl-style regexes, but there are many basic differences. This tag should be used instead of the regex tag, to forestall irrelevant answers from responders who are familiar with regexes but not with Lua.

Using this tag instead of the regex also tag makes it clear that you're not using regexes provided via an imported library.

356 questions
0
votes
1 answer

Lua gmatch Regex Returning Nil

I am trying to select lines excluding the ones defined with keywords Cockos|VSTi|mono|x86|midi|MIDI|\\[vstcache\\] Here is the Lua Regex pattern I am using, but getting a nil when I try to gmatch in Lua script…
shadow24
  • 59
  • 4
0
votes
1 answer

Match string until a character or end

I'm trying to match and return a string between two (or one if there's no closing character, then until the string's end) character. local id = "+@a-@s,@n"; local addOperator = string.match(id, "^[+](.+)(?[-])"); -- should return "@a" if…
szkiddaj
  • 17
  • 4
0
votes
1 answer

Weird matching behaviour and argument interpretation in Lua

Somehow there seems to be a difference, when passing a string in via a variable vs. passing a string via an expression as an argument. I am so confused right now, about how Lua evaluates expressions. In short: I am trying to detect a word, case…
Sewbacca
  • 576
  • 6
  • 17
0
votes
3 answers

LUA error "pattern too complex" - Tabletop Simulator

I have a string and I am trying to extract a particular section of from it using a LUA pattern match. I saved this as regex which you can see here, along with the string and regex syntax which extracts the exact section I want (the green capture…
Mucker
  • 257
  • 3
  • 12
0
votes
1 answer

Extract last part from string

I have a string, which looks like this: local string = 'VALUE1_VALUE2_VALUE3_VALUE4' I would like to get the VALUE4 only using string.match. How can i do this?
Jamifi
  • 1
0
votes
2 answers

how to write a Lua pattern to convert string (nested array) into a real array?

I would like to convert a string into an array (a small map in a game with coordinates, colors, etc.), the string represents a nested array, and I am not sure how to do it. I would like to open an array after the first { , then open an array after…
Leo_xfh
  • 23
  • 4
0
votes
1 answer

Lua Script match multiple word

My first time, I try Lua script, I want to match on string (user-Agent), multiple substring to exclude them when it is match. pattern string is User-Agent pattern, and the multiple string are google, safari and edge local m, err =…
ezceeaaaa
  • 19
  • 5
0
votes
1 answer

Lua variable in pattern match with special characters

I have a problem with a pattern match, when a variable with special characters in the value from regex is used in the match. The code: in_pic_file = 'C:\\Users\\marcus.LAPTOP-01\\RAW\\2021\\20211031\\20211031-_R4_1301.tif' sync_dir_in =…
Marcus J
  • 23
  • 5
0
votes
1 answer

Extracting characters between double quotes

In my project, I need to extract some parameters from a settings file. Below is a section of the line that I am reading, the parameter I need to extract is the Program Prefix. ... ProgramPrefix="" ReceiveTimeout="80000" ... I need to extract what…
xelarim
  • 1
  • 1
0
votes
1 answer

Lua function for string.match multiple words and numbers

If I have a search box and want to find if a string contains certain words (not case sensitive) and/or numbers. search = "Brown lazy 46" textline = "The quick brown fox jumped over 46 lazy dogs" if string.match(textline, search) then result =…
LuaStart
  • 397
  • 2
  • 11
0
votes
1 answer

Lua pattern to remove everything after a word

If I have a string like this. local string = "D:/Test/Stuff/Server/resources/[Test]/SuperTest" How would I remove everything after the word "server" so it will end up look like this local string = "D:/Test/Stuff/Server"
Birk
  • 191
  • 2
  • 12
0
votes
1 answer

Lua: Regex and Lua Patterns

local code = [[ client_script 'Bait.lua' client_script 'Test.lua' --Test ]] how am I gonna make a regex/pattern that takes everything that's between client_script ' and ' --Test
Birk
  • 191
  • 2
  • 12
0
votes
1 answer

Match for several symbols in char-set

Lua's (and any other regex I think) have char-sets that allow matching for any symbol in the set. Is there a way to match several symbols from that set as one? Example text:gsub("foo[^bar]-","") -- matches for any foo that is not followed by 'b',…
IAmVisco
  • 373
  • 5
  • 14
0
votes
1 answer

(LUA) is there any way for me to cut a message and save it inside variables?

i can use string.gsub(message, " ") but it only cuts the words. i searched on http://lua-users.org/wiki/StringLibraryTutorial but i cant find any solution for this there how can i save these words into variables? for example i have message = "fun 1…
0
votes
2 answers

lua match repeating pattern

I need to encapsulate in some way pattern in lua pattern matching to find whole sequence of this pattern in string. What do I mean by that. For example we have string like that: "word1,word2,word3,,word4,word5,word6, word7," I need to match…
Vlad
  • 113
  • 2
  • 9