[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Pattern matching lines starting with double comment characters
From: |
Tapani Tarvainen |
Subject: |
Re: Pattern matching lines starting with double comment characters |
Date: |
Sun, 26 Feb 2023 10:02:28 +0200 |
On Sat, Feb 25, 2023 at 11:57:35PM +0900, Koichi Murase
(myoga.murase@gmail.com) wrote:
> > [...]
> > pn_ere = "^[[:space:]]*([#;!]{2,}|@c|//)[[:space:]]+"
> > [...]
> > pn_ere = "^[[:space:]]*([#;!][#;!]+|@c|//)[[:space:]]+"
>
> The above two both match also #!, !#, #;, ;#, ;!, and !;, which do not
> seem to be requested.
Right you are. Careless of me. Thank you.
> > With egrep (grep -E) you could also do this:
> >
> > pn_ere = "^[[:space:]]*(([#;!])\2+|@c|//)[[:space:]]+"
>
> \2 is undefined in ERE. The back references are only defined in BRE.
> It's an implementation extension and not always available with grep
> -E.
Right. It works with Gnu grep but can't be relied on in general.
> The only portable way is to specify each just the same as you do for //:
>
> pn_ere = "^[[:space:]]*(##|;;|!!|@c|//)[[:space:]]+"
Yes. Assuming the intent is to allow exactly two of the comment
characters. Which the OP apparently wanted, but at least offhand
I can't think of any language that requires blank space after
the comment marker and it is actually rather common to use
more of them at times.
--
Tapani Tarvainen
Re: Pattern matching lines starting with double comment characters, Greg Wooledge, 2023/02/25