lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I vote for just using something like 
string.sub( cap1, 2, 2 )
:-)

The * sign used only for digit and we cannot use it for '[a]' token.
Maybe %b[] may helps, but for me small "tuning" the cap1 value is good
enough.

Best wishes, Denis


-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Theodor-Iulian
Ciobanu
Sent: Friday, October 27, 2006 11:45 AM
To: Lua list
Subject: Re[2]: Need help building a regexp pattern


Hello Denis,

Yes, that helps. Thanks. Not to make it a little bit more difficult,
what about strings like these:

[a] [aaa...] aaaaaaaa...
or
[aaa] a.....

Just like before, but this time the first two captuers are ensclosed
between [], so I'd have to take them into account as well. Is there a
way do this in as single match, or should I use "(.*)%[(.+)%](.*)" and
extract the character I want from the first capture, if it's not nil?

Friday, October 27, 2006, 10:30:58 AM, you wrote:

DP> Hi Theodor!

DP> If I understand you correctly, main goal is to eliminate second call

DP> of string.find(). Although you didn't provide a sample of your 
DP> strings I hope my test sample will be helpful.

DP> Main idea is to use for first capture "(.*)" instead of "(.)". And, 
DP> in case of first type of string you'll receive a symbol and in case 
DP> of second type it will be an empty string. Empty string may be 
DP> easity converted to nil, if it required.

DP> Maybe there's a better solution, which will give you exactly you 
DP> want (nil for the first capture), but at a first sight I suppose my 
DP> version completely fits your needs.

DP> WBR, Denis

DP> -----------------------
DP> m1 = "(.)(.)(.)"
DP> m2 = "(.*)(.)(.)"
DP> str1 = "ABC"
DP> str2 = "BC"

DP> _, _, cap1, cap2, cap3 = string.find( str1, m1 )
DP> print( cap1, cap2, cap3 )
DP> _, _, cap1, cap2, cap3 = string.find( str2, m1 )
DP> if cap1 == "" then cap1 = nil end
DP> print( cap1, cap2, cap3 )
DP> ---------------------

-- 
Theodor-Iulian Ciobanu
jr Virus Researcher

e-mail: tciobanu@bitdefender.com

-----------------------------------------
Trying to secure your every bit
-----------------------------------------


--
This message was scanned for viruses by BitDefender for Linux Mail
Servers. For more information please visit http://www.bitdefender.com/