Author Topic: Regex Question  (Read 1829 times)

0 Members and 1 Guest are viewing this topic.

Offline KaliOfLSTopic starter

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Regex Question
« on: January 17, 2013, 07:05:00 PM »
0
Okay, tossing together something to warm my heart up to regex.. if possible.

Consider these lines:

Code: [Select]
if this then
elseif this then
else end

if breif then
end

function t()
end

local t = function()
end
Let's consider something like this
Code: [Select]
--Lets assume I've opened the file, and will iterate with f:lines()
local sfind = {'if','end','function'}
for line in f:lines() do
   for _,v in pairs(sfind) do
        if line:match(sfind) do
       --I am trying to find and pair if/end counts.  so I'd like to only find 'if', not elseif or words containing if.  this fails.
        end
       if line:match('[ ]*'..sfind)
       --again fails  because I'm not forcing a space.     
       end
       if line:match('[ ]+'..sfind)
       --fails because I have no spaces in front of some lines
       end
   end
end

brutal, I'm sure I've tried others, but can't remember all of them.  I need like a
if nothing OR ( any number of spaces AND no characters) OR ( if any character then require space ) then match token sfind.
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Offline KaliOfLSTopic starter

  • That's "Dr." Kali to you!
  • Sr. Member
  • *
  • Posts: 406
  • Activity:
    0%
  • Reputation Power: 6
  • KaliOfLS has no influence.
  • Gender: Male
  • Respect: +33
  • Referrals: 2
    • View Profile
Re: Regex Question
« Reply #1 on: January 17, 2013, 09:07:22 PM »
0
Problem solved
if line:lower():match('^'..v..'[ (]*') or line:lower():match('[ ]+'..v..'[ (]*') then
R~~~~ B~~~~~~~~ 
^ real life signature for sure

Tags: