Matching "beginning-of-line" using libc++ regex library (C++11)

Viewed 3151

I would like to match all lines that start with a given word, say iheap. If I am not mistaken the regular expression (in ECMAScript syntax) "^iheap.*" should do the trick. However, when I tested this in C++11 using libc++'s regex library, only the first line is matched. So "^..." seems to only match beginning-of-input instead of beginning-of-line.

Here is an example:

#include <string>
#include <regex>
#include <iostream>

using namespace std;

int main() {
        regex rx("^iheap.*");
        string s = "iheap says hello.\niheap says hello again.\n";
        cout << s << regex_replace(s, rx, "IHEAP");
        return 0;
}

Output:

iheap says hello.
iheap says hello again.
IHEAP
iheap says hello again.

Is this a bug of libc++ or am I doing something wrong? Thanks!

Note: I am using Mac OS X Mountain Lion and Apple LLVM Compiler 4.0 (basically a snapshot of clang 3.1 SVN).

2 Answers
Related