From: Srinivas Jonnalagadda Date: 2005-11-06T14:53:09+09:00 Subject: Help requested -- regexp I have a text file with each line representing a 'record'. The line has tab-separated 'field=value' values. *Note*: Not all fields are mandatory in all records. This text file is rather large, and is auto-dumped from another application. Now, I am trying to provide a quick interface to my users to query this file. The interface I am looking at is something on the lines of (field1 > 4) and ((field4 < 2.25) or (field3 > 8.0)) to be typed in the query shell. I had first written something similar to: class Field ... def gen_regexp(cond) regexp = "(md = /#{@name}=(.+?)/.match(_line); md and " regexp += cond.gsub(/#{@name}/, 'md[1].' + @converter_method) # 'to_i'/'to_f' regexp += ')' end ... end This 'generated' regexp would then be substituted in the place of the corresponding parenthesized 'condition'. Once all such substitutions are complete, a query block is generated as: query_blk = eval("lambda { |_line| #{final_regexp} }") This query block is then used in a conventional 'select' on the lines. It worked for the likes of the example above, but started having problems for clauses with multiple fields in each 'condition', like: (field1 > 4) and ((field4 < 2.25) or (field3 + field8 > 8.0)) since the above substitution logic is at an individual field level. Suggestions please. Thanks! Best regards, JS