openframeworks / openframeworks/openFrameworks

add a simple regex function like ofSplitString()

Open
#1,110 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

core feature prelim-analysis
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Todd's example has this code a few times in it by hand, but I'm thinking it's so simple it could be added along side ofSplitString() and would be really useful ? for sure, more string utility functions are helpful, and for basic text parsing, this is great. Poco gives us this for free, so it doesn't seem like a huge stretch to think of something like this, plus find and replace, etc. Would make the regex example much shorter.

p5 has something similar, if that's a helpful argument:

http://processing.org/reference/matchAll_.html

vector < string > ofxRegex::getMatchedStrings (string contents, string regex );
vector < string > ofxRegex::getMatchedStrings (string contents, string regex ){

    vector < string > results;
    RegularExpression regEx(regex);
    RegularExpression::Match match;

    while(regEx.match(contents, match) != 0) {

        // we get the sub string from the content
        // and then trim the content so that we
        // can continue to search 
        string foundStr = contents.substr(match.offset, match.length);
        contents = contents.substr(match.offset + match.length);

        results.push_back(foundStr);

    }
    return results;
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the existing ofxRegex and ofSplitString implementations, then review how the regex example currently performs matching by hand. Add a utility that returns the matched strings for the supplied contents and regex, and confirm the regex example can use it to become shorter.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.