Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2007-11-20
5
Medium Priority
?
290 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 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 84

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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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

688 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