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
2 answers

Processing TSV Files in Lua

I have a very very large TSV file. The first line is headers. The following lines contain data followed by tabs or double-tabs if a field was blank otherwise the fields can contain alphanumerics or alphanumerics plus punctuation marks. for…
3
votes
2 answers

Lua: replace a substring

I have something like str = "What a wonderful string //011// this is" I have to replace the //011// with something like convertToRoman(011) and then get str = "What a wonderful string XI this is" However, the conversion into roman numbers is no…
Red-Cloud
  • 438
  • 6
  • 13
3
votes
2 answers

Lua: substrings

I have a string which can be of any characters. I like to extract only the part between two exclamation marks or before the first or after the last one: str = "what)ever!when(ver!time!is!mo/ey" function getStrPart(str,n) -- return a substring …
Red-Cloud
  • 438
  • 6
  • 13
3
votes
3 answers

Regex pattern issue in lua

I have a URL string and need to get certain word from a match. Example: /school/student/studentname1/detail/55/address/address1 I am able to pass to fetch detail of the needed one like, local s1,s2,s3…
Paka
  • 1,053
  • 11
  • 20
3
votes
1 answer

String match URI with Lua patterns

How do I pattern match these URI's? I need to string match whatever characters are between the first and second slash (1) or any characters that are present after the first slash (2) or just /(3). Note the trailing slash in the first…
BusterX
  • 125
  • 1
  • 7
3
votes
2 answers

Extracting an IP address from a particular string in Lua

I want to extract a particular value from a string . This is my string iptables -t nat -A PREROUTING -p tcp -m tcp --dport 666 -j DNAT --to-destination 192.168.19.55 How can i extract 192.168.19.55 ip address from this string using string.match in…
vkp_stack
  • 157
  • 1
  • 16
3
votes
3 answers

Why doesn't this match non-greedily and give me just the image name?

local s = "http://example.com/image.jpg" print(string.match(s, "/(.-)%.jpg")) This gives me --> /example.com/image But I'd like to get --> image
3
votes
1 answer

Match a word or whitespaces in Lua

(Sorry for my broken English) What I'm trying to do is matching a word (with or without numbers and special characters) or whitespace characters (whitespaces, tabs, optional new lines) in a string in Lua. For example: local my_string = "foo…
nickkoro
  • 374
  • 3
  • 15
3
votes
1 answer

User Agent Pattern Matching in lua

I am new to lua scripting language so just trying my hand into this language. I got one task which will parse browser user agent string and will return browser information. Though i have done lot of R&D on lua to get solid LUA library which does…
Vish
  • 111
  • 1
  • 13
3
votes
1 answer

Lua regex to match pattern in makefile

I'm writing a script to automate the mantainment of my makefile. I need a Lua pattern that matches the following lines: # objects { objects = build/somefile1.o \ build/somefile2.o \ ... build/somefileN.o \ # }…
user6245072
  • 2,051
  • 21
  • 34
3
votes
3 answers

How to use patterns to ignore certain part of an input string in lua?

Background Information I have a csv file with lines that look like this: +11231231234,13:00:00,17:00:00,1111100,12345,test.net +11231231234,,,0000000,23456,test.net +11231231234,18:00:00,19:00:00,1111100,09991,test.net The lua pattern I have right…
Happydevdays
  • 1,982
  • 5
  • 31
  • 57
3
votes
1 answer

How to match a sentence in Lua

I am trying to create a regex which attempts to match a sentence. Here is a snippet. local utf8 = require 'lua-utf8' function matchsent(text) local text = text for sent in utf8.gmatch(text, "[^\r\n]+\.[\r\n ]") do print(sent) …
minerals
  • 6,090
  • 17
  • 62
  • 107
3
votes
1 answer

Capture group in Lua pattern matches literal digit character instead of capture group

I want to extract the VALUE of lines containing key="VALUE", and I am trying to use a simple Lua pattern to solve this. It works for lines except for those which contains a literal 1 in the VALUE. It seems the pattern parser is confusing my capture…
nolan
  • 93
  • 7
3
votes
2 answers

way to set dynamic pattern matcher

Please look into this question Pattern ^u.meta(\.|$) not working as expected which has the expected behavior that I need. CHANGES In pattern ^u.meta(\.|$) or in lua '^u%.meta%f[\0.]' or '^u%.meta%f[%z.]', the change I need is u.meta can be anything…
przbadu
  • 5,769
  • 5
  • 42
  • 67
3
votes
1 answer

Pattern ^u.meta(\.|$) not working as expected

I have this pattern: ^u.meta(\.|$) EXPECTED BEHAVIOUR ^u.meta(\.|$) will match all the roles like: u.meta u.meta.admin u.meta.admin.system u.meta.* Where as it should not match something like below: u.meta_admin u.meta_admin_system I have tested…
przbadu
  • 5,769
  • 5
  • 42
  • 67