Saurabh Sharma
Saurabh Sharma

Reputation: 2341

Simple regex - (Group matching in C++)

I have a file with the following text format:

Blah blah Blahhh<TAB SPACE -(/t character)>1234<TAB SPACE -(/t character)>some other crap blah

The text may look like:

Saturday Evening    1234    Beautiful

I am using the <regex> library, and I want to use capture groups to only capture the "1234".

I tried:

"\\t(\\d+)\\t"

But when I print the results, it shows the "\t" characters along with the numbers. Any ideas?

Upvotes: 2

Views: 240

Answers (2)

DhruvPathak
DhruvPathak

Reputation: 43225

\b\d+\b to include word boundaries.That would ignore the tabs or whitespaces that are matching in your current regex.

http://regexr.com?32a07

Or if you want to match with tabs , use assertions, they will match the tabs, but not capture them :

(?<=\t)\d+(?=\t)

Upvotes: 3

rici
rici

Reputation: 241671

A few details would be useful, like the code you use to do the search and extract the results, but my guess is that you're looking at the wrong match_result index: you should be looking at element 1. See match_results' operator[]

Upvotes: 0

Related Questions