Amerio.Stephane Posted June 13, 2023 Share Posted June 13, 2023 Hi, I need to extract a poart in a String, and RegExp should perfectly suited for that. RegExpPtr reg = RegExp::create(); reg->compile("^[0-9]+:(.*)$"); String test = "12:foobar"; reg->match(test); // returns 1, so it does match! reg->getNumGroups(); // returns 0, should return 1! reg->getGroup(0); // returns "", should return "foobar" What am I doing wrong? (regexp tested OK on https://regex101.com/ ) Link to comment
andrey-kozlov Posted June 14, 2023 Share Posted June 14, 2023 Hello, As far as I can see, match doesn't fill groups. If you replace reg->match with reg->search the code will work as you expect 1 Link to comment
Recommended Posts