[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>&gt; Date: Thu, 11 Nov 201> 0 12:25:15 \
> -0500<br>&gt; From: gsf@research.att.com<br>&gt; To: gsf@res> earch.att.com; \
> olga.kryzhanovska@gmail.com<br>&gt; Subject: Re: [ast-us> ers] Matching a new line \
> in a ~(E), ~(P) regex?<br>&gt; CC: ast-users@r> esearch.att.com<br>&gt; <br>&gt; \
> <br>&gt; On Thu, 11 Nov 2010 18:16> :27 +0100 =?KOI8-R?B?z8zYx8Egy9LZ1sHOz9fTy8HR?= \
> wrote:<br>&gt; &gt;>  What is the m in ~(Em)?<br>&gt; <br>&gt; right, this needs to \
> be doc> umented<br>&gt; its on the todo list<br>&gt; <br>&gt; 'm' turns on th> e \
> standard regex REG_NEWLINE flag<br>&gt; you can see all the '&lt;char> &gt;' \
> &lt;=&gt; REG_* flag mappings in<br>&gt; 	src/lib/libast/re> gex/regcomp.c<br>&gt; \
> <br>&gt; &gt; Olga<br>&gt; <br>&gt; _______> \
> ________________________________________<br>&gt; ast-users mailing list<b> r>&gt; \
> ast-users@research.att.com<br>&gt; 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