FAQ
I am trying to write a regular expression to do the following:

STARThelloEND Some other stuff that shouldnt be part of match
STARTgoodbyeEND

I want to match the STARThelloEND and STARTgoodbyeEND

In cases where there is no END to a START, like:

STARThello Some other stuff that shouldnt be part of match STARTgoodbyeEND

I only want to match STARTgoodbyeEND

With a negative look behind, I can do it like so in
Ruby: http://rubular.com/r/sGnqnCmTUp

However, that operator is not supported in Go. How can I achieve the
desired result?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Jan Mercl at Nov 6, 2014 at 7:29 am
    Regular expressions handle regular languages. Your language is context
    free. You need a parser.

    -j (phone)

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Roger peppe at Nov 6, 2014 at 8:55 am
    It doesn't look context-free to me.
    It's a bit involved, but doesn't this work?

    START([^ES]|E[^N]|E[^N][^D]|S[^T]|ST[^A]|STA[^R]|STAR[^T])*END

    In general though, I wouldn't use a regular expression for this.

    See http://commandcenter.blogspot.co.uk/2011/08/regular-expressions-in-lexing-and.html

    On 6 November 2014 07:29, Jan Mercl wrote:
    Regular expressions handle regular languages. Your language is context free.
    You need a parser.

    -j (phone)

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jan Mercl at Nov 6, 2014 at 9:17 am

    On Thu, Nov 6, 2014 at 9:55 AM, roger peppe wrote:
    It doesn't look context-free to me.
    You're right. However, from the example given I think the OP wants to
    parse XML or HTML or some other markup CF language.

    -j

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedNov 6, '14 at 4:37a
activeNov 6, '14 at 9:17a
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase