Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > RegEx: Looking for something that is NOT there

Reply
Thread Tools

RegEx: Looking for something that is NOT there

 
 
2biased
Guest
Posts: n/a
 
      12-11-2006
Hi,

Not sure that this the right group but as Perl does a lot of RegEx I
thought I might give it a shot.

Consider a large source code project with a lot lines like

const unsigned int a = 0;
const b = 1;
const bool c = FALSE;
const CString d = "10";

etc. As you see the 2nd line has no type specifier which was defaulted
to int in the previous compiler version. The new version requires the
"int" explicitly so I have to find all occurrences for

const <variablename> = <somevalue>;

A expression like

(const)(\s+)(unsigned|int|bool|CString)(.*)(;{1,1} )

gives me lines 1, 3 and 4 as result as expected. But how do I get only
line 2 as result when I only know that it should not contain various
type names (bool, int, float, unsigned ...)?

I tried this for several hours now but didn't get a working solution.
Any ideas on how to do that?

Thanks a lot for your time.
Regards

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      12-11-2006
"2biased" <(E-Mail Removed)> wrote:
> Hi,
>
> Not sure that this the right group but as Perl does a lot of RegEx I
> thought I might give it a shot.


This is the right group only if you plan on using Perl to run your RegExes.
If you are not going to use Perl, this is not the right group. For
example, if we help someone make a Perl Regex to do what they want, then
they complain that the Perl Regex doesn't run in <something other than
Perl>, this really bugs us.

> Consider a large source code project with a lot lines like
>
> const unsigned int a = 0;
> const b = 1;
> const bool c = FALSE;
> const CString d = "10";
>
> etc. As you see the 2nd line has no type specifier which was defaulted
> to int in the previous compiler version. The new version requires the
> "int" explicitly so I have to find all occurrences for
>
> const <variablename> = <somevalue>;
>
> A expression like
>
> (const)(\s+)(unsigned|int|bool|CString)(.*)(;{1,1} )
>
> gives me lines 1, 3 and 4 as result as expected. But how do I get only
> line 2 as result when I only know that it should not contain various
> type names (bool, int, float, unsigned ...)?


I would not try to do it in a single regex, but rather a regex with some
code to go with it.

my %allowed; @allowed{qw/unsigned int bool CString/}=();

while (<>) {
if (/(const)\s+(\S+)(.*)(;{1,1})/ and not exists $allowed{$2} ) {
# do whatever you want to do;
}
};


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      12-11-2006
"2biased" <(E-Mail Removed)> wrote:

> const unsigned int a = 0;
> const b = 1;
> const bool c = FALSE;
> const CString d = "10";


[..]

> gives me lines 1, 3 and 4 as result as expected. But how do I get only
> line 2 as result when I only know that it should not contain various
> type names (bool, int, float, unsigned ...)?
>
> I tried this for several hours now but didn't get a working solution.
> Any ideas on how to do that?


/const\s+\S+\s*=/

const followed by one or more whitespace followed by at least one non-
whitespace followed optionally by whitespace, followed by the assignment
operator.

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
XPath query for <?define something="something" ?> Pekka Järvinen XML 2 04-29-2008 08:12 PM
How to find and replace something that is nested inside something else? alainfri@gmail.com Perl Misc 4 05-31-2007 11:50 PM
var Something= new Something() What does it mean ? pamelafluente@libero.it Javascript 9 10-05-2006 02:43 PM
umm... something... template(s)... something else... pointer(s)... and such... 0.o yah, I'm hopeless and clueless o.0 C++ 4 10-13-2004 10:34 PM



Advertisments