Regular expression

I have a Txt file wich have a line like this:


This line can have as many ELEM? as I want, so I have to read a diferent number of elements each line.

For example:
Line1: {ELEM1}
Line2: {ELEM2,ELEM3}
Line3: {ELEM1,ELEM2,ELEM3}

How can I make a Regular expression so I can put in a Array the diferents elements.


The Regular expression....

Who is Participating?

Improve company productivity with a Business Account.Sign Up

mattropeConnect With a Mentor Commented:
Try this (assuming the line is stored in $line:

if ($line =~ /\{(.*?)\}/) {
  @array = split(',',$1);

Hope this is what you were looking for.
i hope that i have understood ur question.ur ultimate aim is to read lines and populate in to array which
has elem1 as first element,ELEM2 as second and so on
this should work though this is not the most effective way of doing it to my knowledge.u can make it more effective

while($line = <FD>) {#read line from file
@temp =  split(/,/$line) ;
for($i=0;$i<($#temp+1);$++) {
 if($temp[$i] =` /^E.*?(\d)/{
   $array[($1-1)] = $temp[$i]
print @array;
i think u could do evenwithout splitting .i havent tried it out
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.