I've had a recent need for Regex in an experiment of mine, but I just can't seem to figure out the ECMAScript syntax. Here's what I'm trying to accomplish:
I want the user input to be: any number of digits, one space, and any number of digits again. Ex.: "2 3", "34 58" "234234 2341098"
So, I assumed that the Regex pattern would be:
"\d+ \d+.*"
But when I call regex_match(), it yields false every time. I've tried so many variations on this expression, from grouping to using POSIX groups and ranges, but nothing matches.
Can anyone point me out on how to use ECMAScript, or at least to a tutorial (which I've also looked up, but none helped).
I will also say that for some reason, whenever I try to use a character class, or anything using square brackets '[' ']', Regex throws `error_brack'. I'm not sure entirely why that is.
Shouldn't it be "\\d+\\s{1}\\d+" [edit]or "\\d+\\s{1}\\d+\\n*"[/edit] Anyways, I was under the impression that GCC didn't have a full support for regex. You may have to use clang (compiler) or boost (library/header).
I believe g++-4.9 has full regex support. I'm not sure if there's a way of getting that on Windows without building. But building g++ is relatively painless these days so long as you can read the directions :)
Also note that regex_match() attempts to match the entire expression. Chances are you really want to be using regex_search().
I've considered that, but I'm certain that I want the input to ONLY be what I've stated already. If I use regex_search(), if the user types anything else, it will still return true, which is not my goal.
giblit said:
I was under the impression that GCC didn't have a full support for regex.
I'm starting to think that's the case because whenever I use brackets in a Regex Pattern, regex throws exceptions, even when I know for a fact I have matching brackets. I've been salivating over the Boost libraries for awhile now, only daunted by the manual building. I suppose now is time to download it :P
IIRC, GCC's regex support is an incomplete implementation.
Designing a regex engine is notoriously difficult. It is worth your time to do one of the following:
- use an existing regex C library (such as PCRE or the old GNU regex)
- compile Boost's regex, which is very complete and (AFAIK) relatively bug-free
I'm not really sure why GCC maintainers have such difficulty just using Boost's regex. (I'm sure there is a reason, whether valid or not, only I've not cared to find it out.)
You're using an outdated version of G++. Grab version 4.9 if you want real regex support, as 4.9 has everything but regex_traits::transform_primary implemented.