Regular expression

Posted on 2000-02-24
Last Modified: 2010-03-05
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....

Question by:Pampa

Accepted Solution

mattrope earned 100 total points
ID: 2554280
Try this (assuming the line is stored in $line:

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

Hope this is what you were looking for.

Expert Comment

ID: 2554578
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

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cpan issue 1 64
Perl strange behaviour 5 73
transpose into pipe delemited 8 69
Regex rule to match two different url 5 72
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question