Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Meaning of  "(.*)\"  in a pattern.

Posted on 2007-11-20
5
Medium Priority
?
291 Views
Last Modified: 2010-04-21
What do  "(.*)\"  do in the pattern below?


elsif ( $line =~ m/^\|\s+AT\_name\s+\"(.*)\"/ )
{


}
0
Comment
Question by:naseeam
  • 2
  • 2
5 Comments
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 960 total points
ID: 20324012
The parentheses save whatever is matched inside them to $1
The .* matches any character 0 or more times, as many as possible
the \" matches a double-quote, and the \ is not necessary

So, if $line was '| AT_name "something in here"', then $1 would be "something in here"
0
 
LVL 85

Accepted Solution

by:
ozo earned 1040 total points
ID: 20324203
perl -MYAPE::Regex::Explain -e 'print YAPE::Regex::Explain->new(qr/^\|\s+AT\_name\s+\"(.*)\"/)->explain'
The regular expression:

(?-imsx:^\|\s+AT_name\s+"(.*)")

matches as follows:
 
NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  ^                        the beginning of the string
----------------------------------------------------------------------
  \|                       '|'
----------------------------------------------------------------------
  \s+                      whitespace (\n, \r, \t, \f, and " ") (1 or
                           more times (matching the most amount
                           possible))
----------------------------------------------------------------------
  AT_name                  'AT_name'
----------------------------------------------------------------------
  \s+                      whitespace (\n, \r, \t, \f, and " ") (1 or
                           more times (matching the most amount
                           possible))
----------------------------------------------------------------------
  "                        '"'
----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
  "                        '"'
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
0
 
LVL 1

Author Comment

by:naseeam
ID: 20324277
Is $1 perl macro?
0
 
LVL 85

Expert Comment

by:ozo
ID: 20324350
$1 is a perl variable
perldoc perlvar
       $<digits>
               Contains the subpattern from the corresponding set of capturing
               parentheses from the last pattern match, not counting patterns
               matched in nested blocks that have been exited already.
               (Mnemonic: like \digits.)  These variables are all read-only
               and dynamically scoped to the current BLOCK.
0
 
LVL 1

Author Closing Comment

by:naseeam
ID: 31410248
Nice details.  Quick responses.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

916 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