Solved

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

Posted on 2007-11-20
5
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 240 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 84

Accepted Solution

by:
ozo earned 260 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 84

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

740 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