On 9 April 2018 at 03:41, Paul Lalonde <paul.a.lalo...@gmail.com> wrote:
> A ^ normally matches either the start of string or the start of a new line
> (with the m flag).
> I'd like to match only starts of lines, but not starts of strings, ideally
> without changing the regexp.
>
> My source data is in a ReadSeeker, and if I use
> Regexp.FindReaderSubmatchIndex() I can get the first match - always the
> start of string - and then Seek back to the end of that match to get the
> next match.  Sadly, that one also then matches start-of-string, and there's
> no hope of finding my start of line locations.
>
> On a string or []rune I'd ask for FindAll and get a long list of my line
> starts, but on a Reader it seems I'm hooped, as there is no All version.
>
> Any advice? My reader comes from a fairly complex data structure that can be
> read in blocks - I was hoping to avoid managing expressions that might span
> blocks by putting the data through a Reader interface. Is there a better
> way?

I've encountered this issue before with other regexp packages and
needed to adjust the API to make it possible. I don't think it's
currently possible with the Go regexp package. Note that the internal
"input" interface provides a "context" method which provides the
required functionality (almost - the code currently assumes that
position 0 is special).

It would be possible, I think, to add another method to Regexp that
allowed the caller to specify the EmptyOp context at the start of the
of read data, although thinking of a good name for the method might be
difficult.

While we're on the subject, ISTM that FindReaderSubmatchIndex should
really return []int64 not []int. A bit late now though.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to