Giter VIP home page Giter VIP logo

Comments (8)

rafaelcn avatar rafaelcn commented on May 31, 2024 1

Okay, understood. I was kind of looking at the metthod FindNextMatch with narrow eyes. 😝

from regexp2.

dlclark avatar dlclark commented on May 31, 2024

Hi @rafaelcn do you have sample code you can show? I've made a test app with the given expression and inputs and it gives me 12 matches (with no options).

from regexp2.

rafaelcn avatar rafaelcn commented on May 31, 2024

Yes I do.

re := regexp2.MustCompile(`((Art\.\s\d+)[\S\s]*?(?=Art\.\s\d+))`, 0)

if m, _ := re.FindStringMatch(string(content)); m != nil {
	log.Printf("(%d) matches", len(m.Groups()))
        groups := m.Groups()

	for _, group := range groups {
		log.Printf("--> %s \n\n", group.String())
	}

}

from regexp2.

rafaelcn avatar rafaelcn commented on May 31, 2024

Would you care to give the code of the test app?

from regexp2.

dlclark avatar dlclark commented on May 31, 2024

The groups returned from m.Groups() are the sub-matches (things in parentheses) of the match itself. To access all 12 matches you'll need to loop through them like this:

for m, _ := re.FindStringMatch(string(content)); m != nil; m, _ = re.FindNextMatch(m) {
  // m.String() is the text of the whole match
}

from regexp2.

dlclark avatar dlclark commented on May 31, 2024

Glad we got it worked out!

Unrelated: your pattern will also not capture the last Article (number 13) -- because the string ends instead of having another Article.

from regexp2.

rafaelcn avatar rafaelcn commented on May 31, 2024

Yep, I'm aware of that but it doesn't matter that much because the last article is not that important. I'm still in trouble here. not getting all the 12 matches as you told you got. Now I'm getting only seven

from regexp2.

rafaelcn avatar rafaelcn commented on May 31, 2024

Ops, forget what I wrote. I was looking at a different file!

from regexp2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.