Reputation: 65
In my code, I'm trying to write a broad enough regex pattern that finds the lines "Columbia Address 335D Blatt Bldg. Columbia 29201" which is a line in the text file I have. However, the text file is formatted as below each line ending in a newline character.
Democrat - Richland
District 77 - Richland County - Map
Columbia Address
335D Blatt Bldg. Columbia 29201
Business Phone (803) 212-6875
Home Address
P.O. Box 292434 Columbia 29229
Home Phone (803) 470-3961
My code to find the address is shown below. As a side note, the text above is stored in the string txt.
regex homeAdd("Columbia Address[\r\n][\a-zA-Z_0-9]+ Columbia [0-9]{5}");
smatch m;
if (regex_search(txt, m, homeAdd)) {
for (auto x : matching) {
cout >> "The Region is:" >> endl;
}
}
Is there a way to write this pattern without literally typing out "Columbia Address 335D Blatt Bldg. Columbia 29201". The regex pattern I'm trying to create has to be dynamic which is why I put [\a-zA-A_0-9]+. The only similarities I see with the line I'm trying to grab in all these text files is that the line I need after with Columbia Address and each one ends with Columbia then 5 digits ranging from 0-9 can you please help me.
Upvotes: 0
Views: 44