[prev in list] [next in list] [prev in thread] [next in thread]
List: ast-users
Subject: RE: [ast-users] Matching a new line in a ~(E), ~(P) regex?
From: Glenn Fowler <gsf () research ! att ! com>
Date: 2010-11-11 23:48:19
Message-ID: 201011112348.oABNmJaL016390 () penguin ! research ! att ! com
[Download RAW message or body]
I had to look at this for a bit
REG_SPAN allows <newline> to be matched when REG_NEWLINE is set
this script illustrates
---
# ~(E) REG_NEWLINE=0 REG_SPAN=0
# ~(Es) REG_NEWLINE=0 REG_SPAN=1
# ~(Em) REG_NEWLINE=1 REG_SPAN=0
# ~(Ems) REG_NEWLINE=1 REG_SPAN=1
string=$'one\ntwo'
for expr in '.two/AHA' '^two/AHA'
do for mode in E Es Em Ems
do eval 'result=${string/~('$mode')'$expr'}'
printf $'%-3s %-12s %q\n' "$mode" "$expr" "$result"
done
done
---
the output is
---
E .two/AHA oneAHA
Es .two/AHA oneAHA
Em .two/AHA $'one\ntwo'
Ems .two/AHA oneAHA
E ^two/AHA $'one\ntwo'
Es ^two/AHA $'one\ntwo'
Em ^two/AHA $'one\nAHA'
Ems ^two/AHA $'one\nAHA'
---
a difference between the two expressions is . consumes
a string character when it matches and ^ does not
On Thu, 11 Nov 2010 13:51:44 -0500 Finnbarr Murphy wrote:
> What is the difference between REG_NEWLINE and REG_SPAN?
> They seem to be intertwined in some fashion.
> > Date: Thu, 11 Nov 2010 12:25:15 -0500
> > From: gsf@research.att.com
> > To: gsf@research.att.com; olga.kryzhanovska@gmail.com
> > Subject: Re: [ast-users] Matching a new line in a ~(E), ~(P) regex?
> > CC: ast-users@research.att.com
> >
> >
> > On Thu, 11 Nov 2010 18:16:27 +0100 =?KOI8-R?B?z8zYx8Egy9LZ1sHOz9fTy8H> R?= wrote:
> > > What is the m in ~(Em)?
> >
> > right, this needs to be documented
> > its on the todo list
> >
> > 'm' turns on the standard regex REG_NEWLINE flag
> > you can see all the '<char>' <=> REG_* flag mappings in
> > src/lib/libast/regex/regcomp.c
> >
> > > Olga
> >
> > _______________________________________________
> > ast-users mailing list
> > ast-users@research.att.com
> > https://mailman.research.att.com/mailman/listinfo/ast-users
>
> --_31a7c15e-6887-49b8-8bc8-fa5698e53aa3_
> Content-Type: text/html; charset="iso-8859-1"
> Content-Transfer-Encoding: quoted-printable
> <html>
> <head>
> <style><!--
> .hmmessage P
> {
> margin:0px;
> padding:0px
> }
> body.hmmessage
> {
> font-size: 10pt;
> font-family:Tahoma
> }
> --></style>
> </head>
> <body class='hmmessage'>
> <br>What is the difference between REG_NEWLINE and REG_SPAN?<br>They seem t> o be \
> intertwined in some fashion.<br><br><br>> Date: Thu, 11 Nov 201> 0 12:25:15 \
> -0500<br>> From: gsf@research.att.com<br>> To: gsf@res> earch.att.com; \
> olga.kryzhanovska@gmail.com<br>> Subject: Re: [ast-us> ers] Matching a new line \
> in a ~(E), ~(P) regex?<br>> CC: ast-users@r> esearch.att.com<br>> <br>> \
> <br>> On Thu, 11 Nov 2010 18:16> :27 +0100 =?KOI8-R?B?z8zYx8Egy9LZ1sHOz9fTy8HR?= \
> wrote:<br>> >> What is the m in ~(Em)?<br>> <br>> right, this needs to \
> be doc> umented<br>> its on the todo list<br>> <br>> 'm' turns on th> e \
> standard regex REG_NEWLINE flag<br>> you can see all the '<char> >' \
> <=> REG_* flag mappings in<br>> src/lib/libast/re> gex/regcomp.c<br>> \
> <br>> > Olga<br>> <br>> _______> \
> ________________________________________<br>> ast-users mailing list<b> r>> \
> ast-users@research.att.com<br>> https://mailman.research.att.> \
> com/mailman/listinfo/ast-users<br> </body> </html>
> --_31a7c15e-6887-49b8-8bc8-fa5698e53aa3_--
_______________________________________________
ast-users mailing list
ast-users@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic