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
3
votes
1 answer

How to do a Lua Patterns search correctly?

I am trying to do a pattern search, but it doesn't work. I have this code: vars = "CmdTurn.on=off/GetPar.pwd=true" _GET = {} for k, v in string.gmatch(vars, "(%w+)(%p+)(%w+)=(%w+)&*") do _GET[k] = v print(k..":"..v) end After run this code I…
3
votes
1 answer

Lua string.find correct format?

I have quite simple question, but my google research did not help.. I am pretty new to Lua, so.. I have string "XXXX_YYYYYY_zzzzzz" stored in local variable and I want to parse it and get 3 new local variables. Should I use string.find? local str_ =…
LuaLuaLua
  • 33
  • 4
3
votes
2 answers

String parsing using complex patterns

I have a complex string with an unknown number of letters, numbers, and characters. For instance "a83bal*av31-ab+asf3/af1124-xxx.afe-100/araw31/31*xxx.g41.abt.eta+131as*dfa" The goal is to find the string xxx and extract everything after it until a…
Miles Engel
  • 131
  • 2
3
votes
2 answers

Porting POSIX regex to Lua pattern - unexpected results

I have hard time porting POSIX regex to Lua string patterns. I'm dealing with html response from which I would like to filter checkboxes that are checked. Particularly I'm interested in value and name fields of each checked checkbox: Here are…
mzet
  • 577
  • 2
  • 7
3
votes
1 answer

Lua Pattern Matching a pattern

My problem is this. I have a string containing let's say local mystring = "ASD_ASDDFS_SDF_ASDASD as8d76 na879yd" I want to take the part of the string that has the capital letters with the underline. Now normally this would be easy but right now…
Thomja
  • 259
  • 5
  • 15
3
votes
2 answers

Generating hyperlinks from a string

I am trying to create a function that will parse a string and replace and URLs found with an HTML version of that URL. For example, test.com would become
user4872340
3
votes
1 answer

Remove all chars from a string except "a","b","c","d"

I have a string where I want to replace all chars and digits with "", except chars a,b,c, d. Instead of having to write multiple lines of long code like in the example below, is there some other way to write this more…
Richard Avalos
  • 555
  • 5
  • 18
3
votes
1 answer

Lua: String.match/string.gsub - Casing for true/false

I've been trying to figure this out for a while, but I fear I'm not seeing the entire solution quickly, and now I'm needing a fresh set of eyes to accomplish what I need. I have a very particular script for the MUD I play to help me differentiate…
Josh
  • 3,225
  • 7
  • 30
  • 44
3
votes
2 answers

regex replace : if not followed by letter or number

Okay so I wanted a regex to parse uncontracted(if that's what it is called) ipv6 adresses Example ipv6 adress: 1050:::600:5:1000:: What I want returned: 1050:0000:0000:600:5:1000:0000:0000 My try at this: ip:gsub("%:([^0-9a-zA-Z])", ":0000") The…
ShittyAdvice
  • 265
  • 7
  • 18
3
votes
1 answer

Lua pattern to replace any word,character, digit or symbol followed by a paticular string

I want to replace any word, character, digit or symbol (except ; , .) followed by the string "some-word\" in Lua. More like a '*' option in regex. Is there any thing similar to '*' in Lua? Example: some-word\\test ->…
Namitha
  • 355
  • 1
  • 6
  • 17
3
votes
1 answer

tonumber and regex

Given is a (time-value) String like: local dt = "12:34:56" I want to cut this string into hh, mm, ss = "12", "34", "56" therefore I use regex like this: local hh = string.format("%02d", tonumber( dt:gsub(":..:..","") )) local mm =…
jawo
  • 856
  • 1
  • 8
  • 24
3
votes
1 answer

Lua script - find digits in a string

I have a Cisco ASA 8.4 VPN Concentrator. I am trying to use Lua to extract digits from a certificate string coming in and use them in a LDAP lookup with AD for authorization. I found a string that works...sometimes. The string comes in with the…
3
votes
2 answers

Matching a pattern in Lua

I'm trying to match a string which is 9 characters long and will always have digits. The pattern I am trying to match is to see if the string is all 0s or all 1s or all 2s and so on upto all 9s. Can someone help me write this. I just had to consider…
Salman Syed
  • 568
  • 5
  • 9
3
votes
2 answers

Lua string.gsub inside string.gmatch?

I've created this simple example script to output a list of foods. If the food is a fruit then the color of the fruit will be displayed as well. The issue I'm having is in dealing with the irregular pluralization of 'strawberries.' fruits = {apple =…
Eli Bell
  • 227
  • 1
  • 9
3
votes
2 answers

Insert quoted and unquoted parts of string in table

I've been working on this part of a saycommand system which is supposed to separate parts of a string and put them in a table which is sent to a function, which is queried at the beginning of the string. This would look like, for example, !save 1 or…
Alistaire
  • 63
  • 6