C++ :: Searching A MultiMap With Regex

Apr 24, 2014

I have a multimap with over 300k entries defined like so: std::multimap<std::string, std::string> filedata;

Using the following code and std::multimap::equal_range, I am able to successfully search for a word in the multimap and get needed data:

// Data with strings.
data = std::vector<std::string>();
// Get iterators to matched pairs.
std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range(word);
// Go through each matched pair and get needed info.
for (std::multimap<std::string, std::string>::iterator iter = dat.first; iter != dat.second; iter++) {
data.push_back(iter->second);
}

Now, I would like to search the multimap using regular expressions (EX: std::regex("[a-z][a-e]h")). What is the fastest way to do this? Example code may look like:

std::pair <std::multimap<std::string, std::string>::iterator, std::multimap<std::string, std::string>::iterator> dat = filedata.equal_range_with_regex(std::regex("" + word + ""));. Pseudo-code / algorithms will be enough.

View 2 Replies


ADVERTISEMENT

C++ :: How To Control Iterator Of Multimap

Feb 22, 2013

I am running some simulation, in which i need to control the iterator of a multimap, like

multimap<double, int> mapp;
......

int n=6;
for(int i=0; i<5; i++) {
for(auto it = mapp.begin()+i*n; it!=mapp.begin()+(i+1)*n; it++) {
......

However this way of controlling is not possible for multimap. Why and how the make it work? Do I need to overload the operator +?

View 14 Replies View Related

C++ :: Multimap Alphabetically Ordering With Char

Jan 18, 2015

I understand multimaps are key ordered. I have no problems with ints but when I put my char arrays in they are not alphabetically ordered. I must use char array and not <string>. Is it possible to alphabetically order them with char*

39 int c;
40 User *user;
41 char nameH[200];
42 char line[200];
43 int ageH;
44 double wH;

[code]....

View 2 Replies View Related

C++ :: Segmentation Fault On Multimap Iterator

Jan 5, 2015

I have created a multimap for my road points. The key refers to the road number and the values are vec3 points that make up the road.

I am trying to iterate through the values of each key point and create a road segment at each point on the road (except the last), adjust the values to be on the road points and then store them in a std::vector.

The RoadSegment constructor creates 6 vec3 points and pushes them onto a std::vector.

I have a segmentation fault in the line marked in bold
[for(mapIt = it.first; mapIt != it.second; ++mapIt)]

When i take out the lines creating the new objects and pushing them onto the std::vector it works fine.

std::vector<glm::vec3>::iterator SegIt;
for(int i = 0; i < m_genRoads->getKeyValueData().size(); i++)
{
int numberDesired = m_genRoads->getMultimapData().count(i) - 1;

[Code]...

View 1 Replies View Related

C++ :: Create Grading System Using Multimap

Jun 20, 2014

I have an assignment to create a grading system using multimap. It's not completed yet at the moment but whenever i try to compile it tells me "no match for 'operator[]' in lines 56,57,etc. I

#include <iostream>
#include <string>
#include <map>
using namespace std;
class Student {
public:
//--- Constructor
Student (int id = 0, double gpa = 0);

[Code]...

View 3 Replies View Related

C++ :: How To Pair / Multimap (int Pointer To A Function)

May 22, 2012

What is the correct syntax? I tried something like

Code:
class myclass {
multimap<int, void(*)()> mm_fn;
...
void afunction();
...
void anotherfunction(int anint){
mm_fn.insert(pair<int,void(*)()>(anint,afunction));
}
}

and the compiler does not like it.

View 14 Replies View Related

C++ :: Writing Functor - Read Data From A File And Store In Multimap

Mar 29, 2014

How would i write a functor for this code. The code is written to read data from a file and store in a multimap.

The data has numbered lines. E.g.:
1 This is a string
2 This is a string too

So the aim is to store each word in the line with the number and then to enter a word to search for the line numbers it appears on. I do not know how to go about and write a functor

#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdlib>
#include<map>
using namespace std;
int main() {
multimap<int, string>myMap;

[Code] ....

View 4 Replies View Related

C++ :: How To Use Regex Library To Use It In CLI Game

Jan 18, 2015

I want to use C++ regex library, to use it in my lil' CLI game. The aim is to create the template(not C++ template :)) for command(like "go north"). Then, if player writes anything that contains "go", and "north" appearing after that(examples: "go north" "please go north" "Let's go north!" "Princess, I insist that we go to the north") would all be interpreted as simple "go north". I have used a bit of regex in Linux system, but not this ECMAScript regex that C++ uses.I've checked in some online regex tester, that if I write: ".*go.*north.*" then anything I want will be matched; however, I'd like these to be specifically separated by space(the rule is: between north and go there must be at least one character: a space, so that gornorth won't be interpreted as command.).

Bonus points: if it's possible to do that without some kind of black magic, I'd like to achieve following goals:

1)Before go, there can be any amount of characters, but if there is 1 or more characters, the character just before go must be space.
2)In between go and north, there must be at least one character, space. If there are more, then characters right after go and just before north have to be spaces.

View 8 Replies View Related

C/C++ :: Regex - Get Word With Separator

Nov 23, 2014

string skirt = "[\s,.;:!?()\-]+";
regex re(skirt);
sregex_token_iterator it(begin(), end(), re, -1);
sregex_token_iterator reg_end;
for(; it != reg_end; ++it) {
string zodis = it->str();
}
}

I use this to get a word from a large text file. But the problem is, if there is :

however,
It prints out now
however,
but
however
without a separator.

How can I fix that?

View 12 Replies View Related

C# :: Split String With Regex

Aug 27, 2014

I have the the following two strings:

D 1069 Dresden - Neustadt
01069 Dresden - Neustadt

I want to splitt the string and the result should be in both cases:

1069
Dresden - Neustadt

How could i do this with regular expression?

View 6 Replies View Related

C++ :: Use Boost / Regex For Regular Expressions?

Sep 5, 2013

So I need to use boost/regex for regular expressions. someone told me that it needs to be built. the first problem is boost doesn't tell you how to build it and the second is i did sudo apt-get install libboost something. I don't remember the exact name of the package. it installed but i dont know how i would build it when its installed.

View 2 Replies View Related

C++ :: Create Map Containing Regex As Key And Char As Attribute

Mar 27, 2013

I want to create a map contaning a regex as key and a char* as an attribute , like:-

map<regex, char*> res;
res["[[:alnum:]]"] = "alphanumeric text";

but the following error is generated:-

vector<pair<regex,string>>res;
res.push_back(make_pair("[[:alnum:]]","alphanumeric"));

but the error generated is:-

no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=std::pair<std::regex, std::string>, _Alloc=std::allocator<std::pair<std::regex, std::string>>]" matches the argument list
argument types are: (std::pair<const char *, const char *>)
object type is: std::vector<std::pair<std::regex, std::string>, std::allocator<std::pair<std::regex, std::string>>>

View 13 Replies View Related

C++ :: STL Regex Get Position Of Match Within String

Apr 18, 2013

I am trying to get the position of the matches of "Un" in string "Unseen University" in c++ code using STL regex. How can I do this.

i.e. I have following:

std::vector<std::cmatch*>* matches = new std::vector<std::cmatch*>*;
intMyReturnVal = regex("Unseen University", "Un", matches);

I can access a match by

matches->at(i)

and get an Iterator to the beginning of the match by

matches->at(i)->begin()

How can I get the relative position of the match within the entire target string (i.e. "Unseen University", where, in this case, the positions should be 0 and 7)??

View 1 Replies View Related

C++ ::  STL Regex To Match Multiple Substrings

Apr 17, 2013

I am using the (fairly) new STL implementation, which I just became aware of, of regexes. Seems to be an implementation of boost::regex Anyway, I have code, which I would like to use to get ALL matches within a string.

My String is: "Unseen University - Ankh-Morpork"

My regex is (simply): "Un" ;)

using code:

const char *reg_esp = "Un";
std::regex rgx(reg_esp);
std::cmatch matches;
const char *target = "Unseen University - Ankh-Morpork";

[Code] .....

gives output:

"Un" (one line only). How do I get this to match ALL instances of "Un" (i.e. that the output is "UnUn", i.e Un two times)?

View 2 Replies View Related

C# :: Regex / Getting Integer As Long As Its Not In Quotes

May 9, 2014

I am trying to highlight integers in a textbox.

The problem, is that I dont know how to make Regex get Integers no matter what (e.g. even if an =, >,<,>=,<= sign is in front or anything) unless it is encased in a string e.g. "'s or whatever.

My current code does this:

I do not want the numbers to be highlighted if they are in a string.

View 6 Replies View Related

C++ :: Performing RegEx On Open File

Jan 11, 2013

I'm trying to open a file and perform a regex on it, then print the matches, but I'm not sure if I have it right. I think I need to remove the line -

Code:
[for ( std::vector<TCHAR>::iterator It = buffer.begin();It != buffer.end(); It++ )

since I've already copied the file into the buffer, but how do I search the buffer?

Code:
std::ifstream in(TempFullPath, std::ios::in|std::ios::binary);
if( in.fail() )
{
std::cout << "File does not exist or could not open file";
}

[Code]....

View 1 Replies View Related

C++ :: RegEx - Obtain The Alternation Index?

Sep 26, 2014

I was just reviewing some code, and my eye fell on a bit of regex that's intended to parse a date/time stamp into a date and time.

The timestamp uses shorted month names. The regex had all the possible month names to match the entire pattern. If it does, it went through a 2Nd loop to convert the month name into a 1 to 12 numeric value...

This made me wonder, since the regex is already doing the work to verify the alternation, can't it at the same time tell me which of the possible alternations it matched and use that to calculate the numeric value. So basically

Code:
std::regex reMonth("Some more regex stuff here (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec).");
CString strTest("Some more regex stuff here Aug.");
std::cmatch res;
if (std::regex_match(strTest.GetString(), res, reMonth)) {
//int iMonthNum = res[1].something(); // some code here that returns 8 for Aug.
}

Or is there really no other way out than doing a 2nd level verification to figure out the actual month number. (The real regex is a bit more complex than this).

View 3 Replies View Related

C++ :: Output Only Few Files Using Regex From Current Directory

Nov 20, 2013

I'm trying to output only a few files, using regex, from the current directory, this is my main code:

Code:
// main.cpp
{
char * _dir = new char[MAX_PATH];
getcwd(_dir, MAX_PATH);
unique_ptr<CExtractor> _ptr(new CExtractor(_dir));
delete[] _dir;
}

Code:
// CExtractor.cpp
DIR *pdir = NULL;
struct dirent *pent = NULL;
pdir = opendir(_cwd.c_str());
while ((pent = readdir(pdir)) && (pent->d_type != DT_DIR)) {
if (regex_match(pent->d_name, regex(".(in|txt)$"), std::regex_constants::icase)) {
cout << pent->d_name << endl;
}
}
closedir(pdir);

My code is compiled correctly, but when I run my binary, nothings is outputed..here are my files in the current directpory:

aclocal.m4 config.guess config.status depcomp m4 NEWS
AUTHORS config.h config.sub INSTALL Makefile README
autom4te.cache config.h.in configure install-sh Makefile.am src
ChangeLog config.h.in~ configure.ac libtool Makefile.in stamp-h1
compile config.log COPYING ltmain.sh missing

I have a few "in" files

View 1 Replies View Related

C :: Simple Regex To Find Word But Not Containing Some Other Words

Sep 13, 2013

I've been trying to do a RegEx, but I just can't seem to find the solution for it.

Do the following to find Test:

Test55: Will be allowed
TestABC: Will NOT be allowed

Basically, if Test is followed immediately by anything else other than a case-insensitive letter (not [a-zA-Z]), then it will pass.

View 3 Replies View Related

C++ :: Regex Unexpected Matching (Floating Point)

Oct 28, 2014

I have written this regex to match a floating point literal:

(^[[:space:]]*)(([0-9]+.?[0-9]*([eE][+-]?[0-9]+)?)|"
"(.[0-9]+([eE][+-]?[0-9]+)?))([fFdD]?[[:space:]]*)$

and when I match it with string like "123e" or "e2" it works while it shouldn't and I can't find the reason why.

View 2 Replies View Related

C# :: Listbox File Populate Filtered With Regex

Sep 27, 2014

i found somewhere online this code that populate my listbox with file names. Now is it anyhow possible to filter those names before it gets populated by regex ?

Code:

private void PopulateListBox(ListBox lsb, string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach (FileInfo file in Files)
{
lsb.Items.Add(file.Name);
}
}

Call on form load:

PopulateListBox(listBox1, Application.StartupPath, "*.exe");

Now is there way to add regex for filename?

View 5 Replies View Related

C# :: How To Match Regex If Input Was Array Of Strings

May 19, 2014

In the MSDN, it gives an example using Regex.Matches method:

using System;
using System.Text.RegularExpressions;
public class Example {
public static void Main() {
string pattern = "a*";
string input = "abaabb";
foreach (Match m in Regex.Matches(input, pattern))
Console.WriteLine("'{0}' found at index {1}.",
m.Value, m.Index);

[code]......

I am wondering if string input was an array of strings instead, how would I use Regex.Matches?

What I was thinking about doing is having the input array set to ToString(), input.ToString(), but that doesn't seem to work.

View 9 Replies View Related

C# :: Regex For Addition Of Integers And Subtraction Of Complex Numbers

Jan 12, 2015

1.What would regex pattern look like for addition of integers?

2.What would regex pattern look like for subtraction of complex numbers?

View 1 Replies View Related

C++ :: How To Find Position Of First String In Input That Matches Regex

Oct 18, 2014

i want to find the position of the first string in input.txt that matches a regex

// Input.txt
[A-Z]o
Hello everyone, i am John It is rainy today

// Here is my code

string temp; // Store "Hello everyone, i am John
//It is rainy today"
temp.resize(500);
char REGEX[500];
FILE *fi;

[Code]....

View 5 Replies View Related

C Sharp :: Regex Pattern That Takes Only Directory Without File Name

Dec 5, 2014

regex pattern that takes only directory without file name
private void txtDownloadRoot_Validating(object sender, CancelEventArgs e)
{
Regex driveCheck = new Regex(@"([a-zA-Z]:[^/:*;/:?<>|]+)|({2}[^/:*;/:?<>|]+)");
if (!driveCheck.IsMatch(txtDownloadRoot.Text))

[Code].....

View 1 Replies View Related

C++ :: How To Get Standalone Copy Of Regex Part Of Boost Library To Work In Project

Feb 18, 2012

So, I have spent the last week looking googling and researching how to get a standalone copy of the regex part of the boost library to work in a project. This project will be compiled on other machines and I CANNOT have the user install it.

Is there any way to do this?

So far, I have built the regex part: I have both .so files and .a files built. The thing that I'm unsure of is that these were built with gcc and I am using/will be using g++.

I have also finally got the bcp tool to work, and extracted the regex part and all of its dependencies.

I can't get it to compile any way I try to work it. I need this to be in a folder "regex/" folder in my directory.

I have used too many commands to paste them all, but the last I tried was this:

g++ -g -pedantic -Wall -o doit test.C -Iregex/boost/ -Wl,-Lregex/libs/regex/build/gcc/ -static -lboost_regex-gcc-1_47

I have also tried many variations of the above command. Such as using -lboost_regex and lots of other things. Is my whole problem because I'm using an .so built by GCC?

The output of the above command was

/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception':
(.text.__cxa_allocate_exception+0xb4): undefined reference to `pthread_mutex_lock'
/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception':
(.text.__cxa_allocate_exception+0x111): undefined reference to `pthread_mutex_unlock'
/usr/lib/gcc/i686-linux-gnu/4.6.1/libstdc++.a(eh_alloc.o): In function `__cxa_free_exception':

[Code]...

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved