Link to home
Start Free TrialLog in
Avatar of CalmSoul
CalmSoulFlag for United States of America

asked on

regular expression help

What will be the regular expression to read following text file - I would like to make an array

Any text under [element] in one array
Any text under [Docs] in one array
Any text under [Indices.1] in one array
Any text under [Indices.2] in one array


[element]
Type=OU Document with type

[Docs]
1=\ft\ou\ds\comb\5623589556536.TIF
2=\ft\ou\ds\comb\5623589556586.TIF

[Indices.1]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date=  /  /  
mod_acct_num=



[Indices.2]
account_number=9999999
first_name=test user
address=0
sub_class=OUT
linux_date=20000630
bentch_date=  /  /  
mod_acct_num=

Open in new window

Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

While it can be done with regular expressions, it's not the tool for this situation. You'll get 4 strings that you'll need to parse anyway.

You need to write a parser. How to do that depends on your platform.

LE: in no particular language, the logic for the parser would be something like this:
function create_array(file, begining)
  array=[]
  find begining in file
  line=readline
  while line not empty
    array.push(line)
    line=readline
  end while
  return array
end function

open file
element_array=create_array(file, "[element]")
docs_array=create_array(file, "[Docs]")
indices1_array=create_array(file, "[Indices.1]")
indices2_array=create_array(file, "[Indices.2]")
close file

Open in new window


HTH,
Dan
Avatar of CalmSoul

ASKER

Dan

If you can provide me regular expression to get the values before and after "="... I can write the parser... I just need to get the values out...
Try this for a single line with an = character:
preg_match("/([^=]*)=(.*)/", $line, $matches);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dan Craciun
Dan Craciun
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial