473,471 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

regex.h question

Hi,
in the following program, compiled using gcc on Linux, and invoked
as
a.out '[a-z]*' '111'
I get '111' matches '[a-z]*'. What am I doing wrong?

#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>

int main (int argc, char *argv[])
{
regex_t preg;
char errtext[100];
int rc;

if (rc = regcomp(&preg, argv[1], REG_EXTENDED|REG_NOSUB)) {
regerror(rc, &preg, errtext, 100);
printf("%s\n", errtext);
} else if (rc = regexec(&preg, argv[2], 0, NULL, 0)) {
regerror(rc, &preg, errtext, 100);
printf("%s\n", errtext);
} else {
printf("'%s' matches '%s'\n", argv[2], argv[1]);
}
}
Feb 16 '08 #1
5 2986
Follow up to self -
Because the beginning lambda of 111 matches [a-z]*. 111 would not
match '[a-z][a-z]*'.
Feb 16 '08 #2
In article <48**********************************@s19g2000prg. googlegroups.com>,
Knight <kn********@yahoo.comwrote:
>Hi,
in the following program, compiled using gcc on Linux, and invoked
as
a.out '[a-z]*' '111'
I get '111' matches '[a-z]*'. What am I doing wrong?

#include <sys/types.h>
sys/types.h is not part of Standard C.
>#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
regex.h is not part of standard C.
>
int main (int argc, char *argv[])
{
regex_t preg;
char errtext[100];
int rc;

if (rc = regcomp(&preg, argv[1], REG_EXTENDED|REG_NOSUB)) {
regerror(rc, &preg, errtext, 100);
regcomp() and regerror() are not part of standard C.
printf("%s\n", errtext);
} else if (rc = regexec(&preg, argv[2], 0, NULL, 0)) {
regerror(rc, &preg, errtext, 100);
printf("%s\n", errtext);
} else {
printf("'%s' matches '%s'\n", argv[2], argv[1]);
}
}
I get '111' matches '[a-z]*'. What am I doing wrong?
[OT]

It appears to me that what you are doing wrong is thinking that
'111' does *not* match '[a-z]*' . Is it not true that there
is at least one place in '111' that there is an occurance
of zero or more characters in the range a-z ? '*' in a
regular expression means zero or more. Are there not 0
alphabetic letters between the first '1' and the second '1' ?

You may wish to try [a-z]+ or you may wish to anchor your search.
--
"There's no term to the work of a scientist." -- Walter Reisch
Feb 16 '08 #3
Knight wrote:
>
in the following program, compiled using gcc on Linux, and
invoked as
a.out '[a-z]*' '111'
I get '111' matches '[a-z]*'. What am I doing wrong?

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <regex.h>
You are including the above include files, which don't exist in
standard C.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 18 '08 #4
CBFalconer <cb********@yahoo.comwrites:
Knight wrote:
>in the following program, compiled using gcc on Linux, and
invoked as
a.out '[a-z]*' '111'
I get '111' matches '[a-z]*'. What am I doing wrong?

#include <stdio.h>
#include <stdlib.h>
>#include <sys/types.h>
#include <regex.h>

You are including the above include files, which don't exist in
standard C.
No, that's not what he's doing wrong. There is nothing wrong with
using headers that are not defined by the C standard, as long as
you're aware that your code won't be portable to all C
implementations. Not all C programs can be, or should be, 100%
portable.

What he's doing wrong is posting this question to comp.lang.c (which
deals with standard C) rather than to comp.unix.programmer (which
deals with the system that defines the <sys/types.hand <regex.h>
headers). That's a minor offense (I hesitate even to use the word
"offense"), which is easily corrected by telling the OP where to post.
I believe that was already done several days ago.

Chuck, I understand that you download news articles in batches.
That's fine, but if you could post your responses as soon as possible
after downloading the articles, you could avoid a lot of situations
like this one where you post responses to questions that have already
been answered.

--
Keith Thompson (The_Other_Keith) <ks***@mib.org>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Feb 18 '08 #5
Keith Thompson wrote:
>
.... snip ...
>
Chuck, I understand that you download news articles in batches.
That's fine, but if you could post your responses as soon as
possible after downloading the articles, you could avoid a lot
of situations like this one where you post responses to
questions that have already been answered.
If you look at the posting date/time you will find it is accurate
within about 1 or 2 hours. However I have the joy of a news-server
that chooses (at times) to absorb these for something like 5 days
and then actually post them. Drives me nuts. Sooner or later I am
going to dump teranews.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Feb 19 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: engwar1 | last post by:
Not sure where to ask this. Please suggest another newsgroup if this isn't the best place for this question. I'm new to both vb.net and regex. I need a regular expression that will validate what...
8
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
1
by: JM | last post by:
Hi, I am not sure if this is the place to post a REGEX question if not, please indicate me where i can post it?. My question: Given a string like: "Boston. MA. Holidays" I need to define the...
6
by: Sa¹o Zagoranski | last post by:
Hi, could someone help me putting together a regex expression for my problem? I need my search filter to treat spaces and commas in the query the same way no matter how many there are... ...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
2
by: GS | last post by:
How can one avoid capturing leading empty or blank lines? the data I deal with look like this "will be paid on the dates you specified. xyz supplier amount: $100.52 when: September 07,...
4
by: pedrito | last post by:
I have a regex question and it never occurred to me to ask here, until I saw Jesse Houwing's quick response to Phil for his Regex question. I have some filenames that I'm trying to parse out of...
3
by: Peter Proost | last post by:
Hi group first of all I need to say that I almost never use regex hence my question may be stupid. I'm using regex to find all words that start with an @ in a string. But the regex that I figured...
0
by: Tim N. van der Leeuw | last post by:
Hey Gerhard, Gerhard Häring wrote: I so far forgot to say a "thank you" for the suggestion :-) The sample code as you sent it doesn't do what I need to do, but I did look at it for...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.