12 Feb 2019

VS2013 Regular Expression Bug? Maybe

收藏到CSDN网摘
I was trying to parse a large file with blocked data using regex library in VS2013. By working in 2 sites, I installed gcc on my Linux machine and VS2013 on Windows. The expression is very simple as "START_INFO[here is the tricky bit]END_INFO", where each block is clearly enclosed by its own start and end information. Inside the [] (square brackets) I'd like to match ALL valid characters. The . (dot) matches almost all but not the newline character and it becomes literal inside the square brackets []. So I came up with an alternative solution "[\s\S]+?" which should guide the program to search all whitespace and non-whitespace characters until it reaches the END_INFO.


The code worked very well in gcc and game me the desired answer. Interestingly, in VS2013 it never found any match. (well, by saying match I mean using sregex_iterator to search through all matched results.) The workaround is to replace [\s\S]+? with (\s|\S)+?. Why does the regular expression work differently in VS2013? Is this a bug? Maybe.

No comments :

Post a Comment