PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs323] regex understanding
Date: Wednesday, 14 Oct 2020, 07:27:07


    > Message Posted By: Unknown
    >
    > >From my understanding regex in python only returns the first "substring"
    > that matches a given pattern, rather than, for example, creating a list of
    > all words in the input that fit under 1+ capture groups created in the
    > regex pattern. Does this mean we have to iterate through the entire line
    > and run our regex pattern until we reach the end of the line or find an error?

Python is capable of returning all matches, but what would
you do with tthem?  For example, consider

  % X=FOO /c/cs323/Hwk3/mcBash BAR
  (1)$ ${1}$X${1}

If you replace all occurrences of ${1} by BAR, you get

  BAR$XBAR

which expands to
		  
  BAR

if XBAR is not defined.  But the correct output is

  BARFOOBAR

--Stan-
PREV INDEX NEXT