Anonymous wrote:
Steve Luke wrote:
m=video.*
When you have the .* in the first group, you are greedily collecting all characters possible, which in turn is not leaving any characters to be matched to the rest of the String. You should use a more reluctant qualifier like *?.
Nope, that is not correct. The greedy DOT-STAR will "give up" as much as possible of what it has "consumed" in favour of a match.
Looking close - that is true, and even if it weren't the DOT does not match end-of-line so the STAR consumption forced to end just before the end of line.
So I did more tests, and think now the problem is that you assume the line separator for the input is \n, but it may be \r\n. Take for example this code:
When I use this code, the matches would be found as intended and c=IN IP4 88.255.255.77 would be replaced with c=0.0.0.0. When you change the newLine variable to:
such as would be the case if the file were saved with Windows or DOS then the
pattern would not match. To catch both cases you would do
Which would allow \r\n or \n as viable end of line characters. (you don't need the .*? after the new line characters)