[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re[2]: Need help building a regexp pattern
- From: Theodor-Iulian Ciobanu <tciobanu@...>
- Date: Fri, 27 Oct 2006 10:44:49 +0300
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 of
DP> string.find(). Although you didn't provide a sample of your strings I
DP> hope my test sample will be helpful.
DP> Main idea is to use for first capture "(.*)" instead of "(.)". And, in
DP> case of first type of string you'll receive a symbol and in case of
DP> second type it will be an empty string. Empty string may be easity
DP> converted to nil, if it required.
DP> Maybe there's a better solution, which will give you exactly you want
DP> (nil for the first capture), but at a first sight I suppose my version
DP> 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/