Gossamer Forum
Home : General : Perl Programming :

Understanding a regular Expression

Quote Reply
Understanding a regular Expression
 
Hi All ,

I have a small query. I have written a perl script that takes input from a configuration file.

The configuration file is like


MACHINE NAME = X
CONFIG = Y


I need to read this file and enter these values in a hash , as in ...

hash{'MACHINE NAME'}=X


I have seen a regular expression in one of the scripts , to identify the A=B pattern

It is :

if (($name,$value)= /^\s*([^=\s]+)\s*=\s*(.*?)\s*$/ ){

Just need to understand , how does this expression , preserves the value in $name and $ value variables

I understand some part though ...

/^\s* -> for starting whitespaces
([^=\s]+) --> ?? whats this ??
\s* -> white spaces before '='
=\s* -> white spaces after '='
(.*?) -> $value
\s* --> =\s* -> white spaces after $value
$/


Thanks
Subject Author Views Date
Thread; hot thread Understanding a regular Expression gpta_varun 15907 Jul 13, 2010, 10:46 PM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15580 Jul 14, 2010, 12:15 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15597 Jul 14, 2010, 12:38 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
gpta_varun 15571 Jul 14, 2010, 12:43 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15591 Jul 14, 2010, 12:47 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15605 Jul 14, 2010, 1:00 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15577 Jul 14, 2010, 1:07 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15564 Jul 14, 2010, 1:09 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15558 Jul 14, 2010, 1:13 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15593 Jul 14, 2010, 1:27 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15630 Jul 14, 2010, 1:29 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15574 Jul 14, 2010, 1:33 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15600 Jul 14, 2010, 1:39 AM
Post; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15523 Jul 14, 2010, 1:41 AM
Thread; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15596 Jul 14, 2010, 2:09 AM
Thread; hot thread Re: [Andy] Understanding a regular Expression
gpta_varun 15574 Jul 14, 2010, 4:55 AM
Post; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15531 Jul 14, 2010, 4:57 AM
Post; hot thread Re: [gpta_varun] Understanding a regular Expression
Andy 15547 Jul 14, 2010, 12:44 AM