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


ADVERTISEMENT

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

Visual C++ :: Menu Item Separator

Aug 6, 2014

I'm using this tutorial for making an owner draw menu. [URL] ...

When I go into the .rc file and remove all of the MENUITEM SEPARATORs all the menu options are squished to the left of the menu as in the screenshot. As long as there is just one MENU SEPARATOR anywhere the menu is fine. If I could make the application without MENU SEPARATORs that would be awesome.

View 7 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C :: Display Function Displays All Letters Of Word Entered Instead Of Word Itself

Feb 18, 2013

I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.

Code:

//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;

[code]....

View 1 Replies View Related

C++ :: Program That Reads A Word From User And Then Print (cout) This Word

Oct 24, 2013

I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:

Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().

View 7 Replies View Related

C/C++ :: Opening Word Document In Turbo Or Any Program In Word Format

Mar 20, 2013

I have a problem to open word document into turbo c++. i don't know how to open if the documents are in word format.

View 1 Replies View Related

C/C++ :: Convert 1st Letter Of Each Word To Uppercase And Then Display Only The Last Word?

Dec 27, 2013

I want a program to display as follows..

if i enter mohandas karamchand gandhi i want output as M K Gandhi.....

i want the c++ code for this program..my error is i am not able to erase the letters of first 2 words..ie my output is Mohandas Karamchand Gandhi..

View 2 Replies View Related

C++ :: Simple Word Counter - Show Repetition Of Word

Apr 25, 2012

I've taken part the text into 1 word per line, but I can't figure out how to printf every word only once and then add (%d) in the end to show how many repetitions of that word there are.

Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main(){
char *oneword;

[Code] ....

View 3 Replies View Related

C :: How To Find Word And Insert Another Word After That In Text

Dec 20, 2013

I have text (string) and I want to find a given word (it's ok!) and then insert another given word after the first word. The original string is beeing copied into a new string. But something is going wrong!!! Where is my mistake?

(I have some patches...)

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//insert "new_word" after each occurence of "word"
int main(){
char A[100]="In the sentence words the and the.";

[Code]...

View 8 Replies View Related

C++ :: Fstream Class Not Reading Word For Word

Aug 6, 2013

int countTextWords(ifstream * file)
{
string textWord;
int wordCount = 0;
while((*file) >> textWord)
{
wordCount++;
}
return wordCount;
}

for some reason, (*file) >> textWord will not read words into the string. What am I doing wrong?

View 9 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++ :: 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 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++ :: 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++ :: Word By Word From A Line In File?

Aug 14, 2014

ow to read word by word from a line in file into struct. Say for example:

12345 Joe Lim KH879.00
12233 Kay Suet Yee35.98

to

struct master {
unsigned short int IDnum;
char name[30];
float salesCustomer;
};

View 1 Replies View Related







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