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
ADVERTISEMENT
May 8, 2014
I am trying to create a custom ValidationAttribute in my c# .net code. I have done a lot of searching and have code that should be working but the IsValid method is not firing as far as I can tell.
Model code:
[Required(AllowEmptyStrings = false, ErrorMessage = "required")]
//[Range(2014, 2100, ErrorMessage="Please enter a valid year.")]
//[RegularExpression(@"^d{4}$", ErrorMessage = "Please enter a valid year.")]
[ValidYear(ErrorMessage="Please enter one >= 2014")]
[Display(Name = "Exp. Year")]
public string expYear { get; set; }
And this is the class in that same model:
public class ValidYearAttribute : ValidationAttribute {
protected override ValidationResult IsValid(object value, ValidationContext validationContext){
return new ValidationResult("Something went wrong");
}
}
Why the IsValid is not firing.
View 3 Replies
View Related
Apr 3, 2015
I would like to know how can i set a constant attribute in the constructor. This attribute is an int value that cannot be changed.
For instance:
class Test {
public:
const int x;
public:
Test(const int val);
[code].....
With this code i get compile error!
View 5 Replies
View Related
Sep 6, 2014
I have tried googling, so, reddit, irc, and various other forums. Anyways, I am writing a todo list app in c. It generates an xml tree that looks something like this: [URL]... . The problem where I am struggling, is in the function todo_complete, I try to make the attribute of an item switch from false to true. it does it without error, but I can't make it stay that way. here is the code: [URL]...
View 3 Replies
View Related
Dec 9, 2013
I'm having the same problem : [URL] .....
Though, my vector isn't one of int, it is a vector of objects from another class and NetBeans won't compile it.
#include <cstdlib>
#include<vector>
#include <string>
#include<iostream>
using namespace std;
class estoque{
[Code] .....
View 3 Replies
View Related
Aug 2, 2013
I have a input record like
acct|N|Y|N|N|rose@gmail.com
Now I need to create a logic to append a code to the end of the file using the following matrix rules.
00NNNN
01NNNY
02NNYN
03NNYY
04NYNN
05NYNY
06NYYN
07NYYY
[code].....
In the above example these four flags are "N|Y|N|N", so I need to append the matching code at the end of file "04".
desired output :
acct|N|Y|N|N|rose@gmail.com|04|
as it matches code '04':
04NYNN
View 5 Replies
View Related
Mar 28, 2014
I would like to have a program with a 5 mb string embedded in it kind of like this:
Code:
const char *c;
c = (const char*)"BEGIN_STRING_HERE, (5 MB of arbitrary values here)";
Is it possible to generate this string at compile time? Maybe with a macro? I'm trying to avoid a source file with a 5 mb string in it.
View 3 Replies
View Related
Mar 27, 2013
I would like to modify attributes like modification/creation dates.The function is correctly working as if I type in "ls -al", the timestamp is correct. But when using my program to read these attributes, it returns the "real" modification/creation date. Here is the function that shows the timestamp :
Code:
time_t t = sb.st_mtime; struct tm tm = *localtime (&t);
char s[32];
strftime (s, sizeof s, "%d/%m/%Y %H:%M:%S", &tm);
printf ("%-14s %s", lecture->d_name, s); And here is the code for modifying the timestamps : Code: void modifyAttributes(char * file, int mtime, int atime)
}
[code]....
View 9 Replies
View Related
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
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
View Related
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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