Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Lua Regex with groups — Gideros Forum

Lua Regex with groups

tpropertproper Member
edited January 2019 in General questions
If I have a string like this:
local s = "X=5 and Y=2 and X=2 and Z = 4 and B = 4 and X = 9"
How can I parse out all the X values? In other languages you do something along the lines of:
pattern = (X=(\d{1,10}))
and then get all the groups that match.

How can I do this in Gideros Lua?


  • Figure it out...goes something like this:
    local read_in = "1,2,3"
    local numbers = {}
    local cnt = 0
    for n in string.gmatch (read_in, "%d+") do
      numbers[cnt] = n
      print("match: " ..n)
      cnt = cnt + 1
    +1 -1 (+2 / -0 )Share on Facebook
  • You should do an article for the blog on this...
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
  • I'm not sure I understand the code well enough to write an article. I only understood it enough to do some simple things.

    In the end, I was using the regex to parse a json object but I found LunaJson which does it for me. So I ended up using that. But I am glad I found the regex stuff.
  • piepie Member
    Accepted Answer
    @tproper if you just need to read and write json files gideros has a native json plugin http://docs.giderosmobile.com/reference/plugin/json
    From the project tree on the left, right-click on Plugins and add it - keep in mind that if you need to test on device you will need to build your own player.
  • hgy29hgy29 Maintainer
    Json plugin is usually included in prebuilt players

    Likes: pie

    +1 -1 (+1 / -0 )Share on Facebook
  • Oh, wow. Cool. I'll look into that.
Sign In or Register to comment.