boost-regex

How can I find the index in a string that matches a boost regex?

How can I find the index in a string that matches a boost regex? ...

Why does my Boost.Regex search report only one match iteration?

I am trying to find out how many regex matches are in a string. I'm using an iterator to iterate the matches, and and integer to record how many there were. long int before = GetTickCount(); string text; boost::regex re("^(\\d{5})\\s(\\d{8})\\s(.*)\\s(.*)\\s(.*)\\s(\\d{8})\\s(.{1})$"); char * buffer; long length; long count; ifstream ...

boost::regex segfaults when using capture

I get a seg fault for the simple program below. It seems to be related to the destructor match_results. #include <iostream> #include <vector> #include <string> #include <boost/regex.hpp> using namespace std; int main(int argc, char *argv) { boost::regex re; boost::cmatch matches; boost::regex_match("abc", matches, re.assi...

Issues compiling boost programs using cygwin

UPDATE: Found a way to make it compile, see below. Hello, I'm having issues compiling boost programs under cygwin. I've installed the default boost and g++ packages from the cygwin project's setup.exe. On my Linux systems, I can compile a program reg.cpp using the following: g++ -I/usr/include/boost -lboost_regex -o reg reg.cpp On c...

Boost.Regex oddity

Hi, Does anyone have any idea why the following code would output "no match"? boost::regex r(".*\\."); std::string s("app.test"); if (boost::regex_match(s, r)) std::cout << "match" << std::endl; else std::cout << "no match" << std::endl; ...

TextMate Snippet to Mirror Only Matched Characters

I have been trying unsuccessfully to mirror text that only matches "a-z0-9" using the following code: ${1/[a-z]/$0/}${1} After the snippet has been tab triggered I would expect to type "$test" and see "test" mirrored. Any clues? Many thanks! ...

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match value. This is in C++, so I went with Boost, but if another common regex library matches my needs better let me know. I found some .NET (C#...

Boost::Regex DOTALL flag

Is there a DOTALL matching flag for boost::regex? The documentation shows: static const match_flag_type match_not_dot_newline; static const match_flag_type match_not_dot_null; but no mention of regular DOTALL. I'm trying to match a python regular expression written as re.compile(r'<a(.*?)</a>', re.DOTALL) ...

When trying to include '#include <boost/regex.hpp>' I get: 1>LINK : fatal error LNK1104: cannot open file 'libboost_regex-vc100-mt-gd-1_39.lib'

Not sure why i get that, I downloaded libs from here and while I have a lib called 'libboost_regex-vc90-mt-gd-1_39.lib I don't have one which is called 'libboost_regex-vc100-mt-gd-1_39.lib', renaming the one with vc90 to vc100 works but I'm not sure if this is the ideal solution? ...

Boost regexp - null-termination of search results

boost::regex re; re = "(\\d+)"; boost::cmatch matches; if (boost::regex_search("hello 123 world", matches, re)) { printf("Found %s\n", matches[1]); } Result: "Found 123 world". I just wanted the "123". Is this some problem with null-termination, or just misunderstanding how regex_search works? ...

fatal error LNK1104: cannot open file 'libboost_regex-vc90-mt-gd-1_42.lib'

i'm trying to use boost regex within my program the problem is i get this error... the only installation step i did was to add: "C:\Program Files\boost\boost_1_42" into the Additional Include Directories... i'm using VS2008... trying to implement this: #include <iostream> #include <string> #include <boost/regex.hpp> using namespace s...

Boost regex and confusing errors

I'm trying to use Boost regex to see if something has an integer in it. One of the examples on this page is bool validate_card_format(const std::string& s) { static const boost::regex e("(\\d{4}[- ]){3}\\d{4}"); return regex_match(s, e); } There's also a presumably working example here. But when I try it on my machine, I get f...

getting names subgroups

Hi All I am working with the new version of boost 1.42 and I want to use regex with named sub groups. Below an example. std::string line("match this here FIELD=VALUE in the middle"); boost::regex rgx("FIELD=(?<VAL>\\w+)", boost::regex::perl ); boost::smatch thisMatch; boost::regex_search( line, thisMatch, rgx ); Do you know how to g...

How can I convert Perl regular expressions to boost regular expressions?

What is equivalent to perl expression: /ing$|ed$|en$/ in boost regular expression? Words end with ing or ed or en should match with reg expression in boost! ...

Regular expression quantifier questions

Hello, Im trying to find a regular expression that matches this kind of URL: http://sub.domain.com/selector/F/13/K/100546/sampletext/654654/K/sampletext_sampletext.html and dont match this: http://sub.domain.com/selector/F/13/K/10546/sampletext/5987/K/sample/K/101/sample_text.html only if the number of /K/ is minimum 1 and maximum ...

Problem with boost::find_format_all, boost::regex_finder and custom regex formatter (bug boost 1.42)

I have a code that has been working for almost 4 years (since boost 1.33) and today I went from boost 1.36 to boost 1.42 and now I have a problem. I'm calling a custom formatter on a string to format parts of the string that match a REGEX. For instance, a string like: "abc;def:" will be changed to "abc\2Cdef\3B" if the REGEX contains "...

How do I insert format str and don't remove the matched regular expression in input string in boost::regex_replace() in C++?

I want to put space between punctuations and other words in a sentence. But boost::regex_replace() replaces the punctuation with space, and I want to keep a punctuation in the sentence! for example in this code the output should be "Hello . hi , " regex e1("[.,]"); std::basic_string<char> str = "Hello.hi,"; std::basic_string<char> fmt ...

Removing unnecessary parentheses in a regular expression

Suppose I have (in a javascript regular expression) ((((A)B)C)D) Of course that really reads ABCD Is there an algorithm to eliminate unnecessary parentheses in a string like that? ...

How can I use Boost::regex.hpp library in C++?

I tried to use Boost library but I failed, see my code: #include "listy.h" #include <boost/regex.hpp> using namespace boost; ListyCheck::ListyCheck() { } ListyCheck::~ListyCheck() { } bool ListyCheck::isValidItem(std::string &__item) { regex e("(\\d{4}[- ]){3}\\d{4}"); return regex_match(__item, e); } When I tried to com...

How do I get the regex matched value using Boost.Regex?

I'm trying to extract the domain from a URL. Following is an example script. #include <iostream> #include <string> #include <boost/regex.hpp> int main () { std::string url = "http://mydomain.com/randompage.php"; boost::regex exp("^https?://([^/]*?)/"); std::cout << regex_search(url,exp); } How do I print the matched value? ...