I have the following code:
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
string s = "hello";
regex e (".*");
cout << boolalpha << regex_search(s,e) << endl;
return 0;
}
Every time I compile/run it, it prints false
. I have also tried to replace regex_search(s,e)
with regex_search(s.c_str(),e)
.
I have also changed regex e (".*");
to:
1) regex e ("");
2) regex e ("hello");
3) regex e ("^.*$");
4) regex e ("^.+$");
5) regex e ("^hello$");
6) regex e (".ell.");
7) regex e ("ell");
And all of these printed false
as well. However, when I use regex_match()
instead of regex_search()
, expressions number 0 (original), 2, 6
return true
, which means regex_match()
works just fine;
My OS is Microsoft Windows [Version 10.0.16299.125]
My IDE is Code::Blocks 13.12
The compile/link commands are (I removed path info in this post):
-------------- Build: Debug in main (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -std=c++11 -Wall -c main.cpp -o main.o
mingw32-g++.exe -o main.exe main.o
Output file is main.exe with size 1.62 MB
Process terminated with status 0 (0 minute(s), 2 second(s))
0 error(s), 0 warning(s) (0 minute(s), 2 second(s))
-------------- Run: Debug in main (compiler: GNU GCC Compiler)---------------
Checking for existence: main.exe
Executing: "cb_console_runner.exe" "main.exe"
Process terminated with status 0 (0 minute(s), 1 second(s))
The question is simple: What am I missing/doing wrong?