Solved

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

Posted on 2007-11-20
5
289 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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

627 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