Yes, sure. That should work: # \w+ if you really will feed it line-by-line, or else you will have to have more complex expression https://regex101.com/r/pC9qV7/1
Is there any specific requirement for regular expression to work ? I have made sure that the compiler that I am using is supporting the C++11 standard.
It ws the question. I stillnot get exact rules by which you need to mat patterns. A larger sample of what should and what should not be matched would be good.
By the way, do you really need to match control characters? There should be none in normal text.
This is simplified regex, it should work like yours:
captures the escape characters that may sit at the beginning or end of the line.
Which characters? Technically there should not be any in text file. I just want examples of such lines.
() is a capture group. Used if you want to extract something from string and not simply check if it follows a pattern
[] is a class. Inside it you would group all characters wich should be alternatively matched https://regex101.com/ Check the quick reference in lower-right corner
I have a source that behaves differently in different os while reading files. I have a file in the following format:
1 2 3 4 5 6
# Size x
124.0
# Size y
124.0
# Size z
125.0
When I read the lines using getline function, I found that \n \r characters are read along. They are taken care of at visual studio, but not in Linux. I really do not know why . For example, while reading the first line using getline() function , I get "# Size x\r" inside the string. I found it while debugging.
This is one of the reasons I have included the control characters in the regular expression.
WIndows uses \r\n to denote end of line, Unix uses \n. Old Macs uses \r. In your case you might want to just check if last character in line is \r after getline and remove it if so. No other changes needed.
This regex is enough to match your line with or without /r at the end: $\s*#\s+[a-zA-Z] . (line start, any amount of whitespace characters, #, at least one whitespace character, one alphabet characters, unspecified) If there another constraints on line, you might introduce them in regex.