FAQ
Since GO does not support backreferences in regexp support, what does one
do in they wish to have a regular expression in which use of backrefrences
is the natural way to go. Example, find and eliminated repeated words,
something that I can do in PERL via:

$_="alpha:beta:beta:gamma:gamma:gamma:delta:eta:eta";
s/(\b[:\w]+\b)(?:\s*\1)+/$1/g;
print $_, "\n"; # output is: alpha:beta:gamma:delta:eta

Are there no other unofficial packages for GO that support this capability?
I have read various papers about how GO's regexp use more
stable/predictable worst case run times, but lack of backreferences seem
like a serious issue to me, coming from a Perl world as I do.

Gautam

--
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

  • Ian Lance Taylor at Dec 17, 2014 at 6:53 pm

    On Wed, Dec 17, 2014 at 10:44 AM, wrote:
    Since GO does not support backreferences in regexp support, what does one do
    in they wish to have a regular expression in which use of backrefrences is
    the natural way to go.
    Go is a Turing complete programming languages. Regular expressions
    are not. When something is too complex to express as a regular
    expression, write some code.

    Example, find and eliminated repeated words,
    something that I can do in PERL via:

    $_="alpha:beta:beta:gamma:gamma:gamma:delta:eta:eta";
    s/(\b[:\w]+\b)(?:\s*\1)+/$1/g;
    print $_, "\n"; # output is: alpha:beta:gamma:delta:eta
      last := ""
      a := strings.Split(str, ":")
      var b []string
      for i, s := range a {
       if s != last {
        b = append(b, s)
        last = s
       }
      }
      return strings.Join(b, ":")

    I think many people will find that clearer than the regular
    expression. It's probably more efficient too.

    Are there no other unofficial packages for GO that support this capability?
    I have read various papers about how GO's regexp use more stable/predictable
    worst case run times, but lack of backreferences seem like a serious issue
    to me, coming from a Perl world as I do.
    http://godoc.org/?q=pcre

    Ian

    --
    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.
  • Ed Pelc at Dec 17, 2014 at 7:14 pm
    I'd highly suggest reading this <http://swtch.com/~rsc/regexp/regexp1.html>article.
    It's very interesting and it tells you a lot about the reasons behind how
    they implemented go's regexp package. Basically they choose a nice simple
    way to implement regexp that gives you performance directly proportional to
    the length of your input. However because you can't implement all of the
    regexp's extensions and maintain this performance.
    On Wednesday, December 17, 2014 1:44:53 PM UTC-5, ghth...@gmail.com wrote:

    Since GO does not support backreferences in regexp support, what does one
    do in they wish to have a regular expression in which use of backrefrences
    is the natural way to go. Example, find and eliminated repeated words,
    something that I can do in PERL via:

    $_="alpha:beta:beta:gamma:gamma:gamma:delta:eta:eta";
    s/(\b[:\w]+\b)(?:\s*\1)+/$1/g;
    print $_, "\n"; # output is: alpha:beta:gamma:delta:eta

    Are there no other unofficial packages for GO that support this
    capability? I have read various papers about how GO's regexp use more
    stable/predictable worst case run times, but lack of backreferences seem
    like a serious issue to me, coming from a Perl world as I do.

    Gautam
    --
    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
postedDec 17, '14 at 6:46p
activeDec 17, '14 at 7:14p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase