views:

67

answers:

2

I'm working in lua, and i need to match 2 parts of a line that's taken in through file IO. I'm inexperienced with regexes and i'm told lua doesn't have full regex support built in (but i have a library that provides that if need be). Can someone help me with building regexes to match the parts necessary?

 "bor_adaptor_00.odf" 3.778
      ^^^^^^^^^^^^^^      ^^^^^
         i need this in      and this in
         a string            a number
+2  A: 
^"(.*?)"\s+(\d[\d.]*)$

Explanation:

  • ^ = line start
  • "(.*?)" = save everything between " and " to a capture group
  • \s+ = any number >= 1 of whitespace chars
  • (\d[\d.]*) = a digit followed by more digits or dots
  • $ = end of line

No idea how to use that in lua, but should help to get you started.

On the other hand, this is a really simple string, so it could be a good idea to parse it without regular expressions.

KiNgMaR
You're right, i think i can use lua's tools to simply parse it down to a number and a word, and go from there
RCIX
+3  A: 

I made an example:

s = '"bor_adaptor_00.odf" 3.778'
val1, val2 = string.match(s,'(%b"")%s*([.0-9]*)')
print(val1, val2)

output:

"bor_adaptor_00.odf"    3.778
Nick D