Regular Expression Negation not working In C++.

S

sk.rasheedfarhan

Hi ,
I am using regular expression in C++ code, [this C++ code has
downloaded from internet]. Negation is not working in the down loaded
code. [Negation means: [^abc] matches all characters except "a", "b",
and "c]

So I am in dilemma can negation work in C++ code.

If negation works in C++ code, can any one give me a sample code, That
will be benefit for me.

Thanks in Advance.
Rs.
 
R

Rolf Magnus

Hi ,
I am using regular expression in C++ code, [this C++ code has
downloaded from internet]. Negation is not working in the down loaded
code. [Negation means: [^abc] matches all characters except "a", "b",
and "c]

C++ doesn't (yet) contain a regular expression parser, so you have to ask at
a place where the library you're using for regex parsing is discussed.
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

Hi ,
I am using regular expression in C++ code, [this C++ code has
downloaded from internet]. Negation is not working in the down loaded
code. [Negation means: [^abc] matches all characters except "a", "b",
and "c]

So I am in dilemma can negation work in C++ code.

Sure it can.
If negation works in C++ code, can any one give me a sample code, That
will be benefit for me.

Problem is, there are no regular expressions in standard C++, which
means that whatever you are using is non-standard, which makes it off-
topic here. You should probably consult the documentation of the regex
package you have downloaded, and see if there are any special
considerations regarding negation.
 
P

Pete Becker

I am using regular expression in C++ code, [this C++ code has
downloaded from internet]. Negation is not working in the down loaded
code. [Negation means: [^abc] matches all characters except "a", "b",
and "c]

So I am in dilemma can negation work in C++ code.

If you're using TR1, its regex class deals just fine with negated
character sets.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
D

David Harmon

On 20 Feb 2007 07:17:43 -0800 in comp.lang.c++,
(e-mail address removed) wrote,
Hi ,
I am using regular expression in C++ code, [this C++ code has
downloaded from internet]. Negation is not working in the down loaded
code. [Negation means: [^abc] matches all characters except "a", "b",
and "c]

So I am in dilemma can negation work in C++ code.

Yes, of course it can. You made a simple mistake in your code, which
nobody can help you with because you DIDN'T POST THE CODE.

You have no question about C++ code here. You may possibly have an
problem with the particular regular expression code you downloaded.
Since you did not even mention what it is or where you got it, how in
the world do you expect anyone to possibly help you with that?
If negation works in C++ code, can any one give me a sample code, That
will be benefit for me.

I shouldn't, because your post is in complete violation of all the all
the rules under "[5.8] How do I post a question about code that doesn't
work correctly?" in Marshall Cline's C++ FAQ. It is always good to
check the FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/


#include <iostream>
#include <string>
using namespace std;
#include <boost/regex.hpp> // <-- http://www.boost.org
int main()
{
string line;
boost::regex rexp("([^abc]*)");
boost::smatch tokens;
while (getline(cin, line)) {
if (boost::regex_search(line, tokens, rexp)) {
cout << tokens.str(1) << " => " << line << '\n';
}
}
}
 
S

sk.rasheedfarhan

Hi
My problem is, I am running my C++ code [for specifically coded for
Regular expressions ] and it is not giving good results for negation
of a regular expressions.

And my C++ code is Downloaded one here is the URL
http://src.opensolaris.org/source/xref/sfw/usr/src/cmd/less/less-381/regexp.c#regnode

I have checked Negation part related code. But I am not clear with my
problem as well with code. Here are my inputs and results

Regular expression :^[^\n]*?102 (.*?)\n
Regular expression Explanation: Any thing before 102 Other than new
line and after 102 a blank space, any thing minimal matches and new
line followed.

Input:102\b\n
Input explanation : 102 blankspace and Newline.

Result :False.


But for this input, it has give the Result as True. But it given wrong
Result.

I check the same thing with this URL http://regexlib.com/RETester.aspx


So please can any body sort out where is the problem in the above code
or can any one give me the best code which work for universal Regular
expression format.

Regards,
Rs.
 
J

John Harrison

So please can any body sort out where is the problem in the above code
or can any one give me the best code which work for universal Regular
expression format.

You've already been given the link.

http://www.boost.org/libs/regex/doc/index.html

I don't know what universal regular expressions are but this library
supports perl regular expressions, posix extended regular exprssions and
posix basic regular expressions.

john
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top