Regular expression for numeric

C

cybernerdsx2

Hi,

I would like to use regex.h to search for a pattern like the following:

"v1.2.54"

how can I achieve that?
 
B

balasam

cybernerdsx2 said:
Hi,

I would like to use regex.h to search for a pattern like the following:

"v1.2.54"

how can I achieve that?
Dear friend,
You will use the "strstr() " function for search the
pattern.Its syntax is
strstr(s,t)
-It search the pattern "t" in the
string "s".
We have to include the user defined files ,then you create the file and
include like this
#include "regex.h".
Still you have you doubt mail to me.
 
C

cybernerdsx2

Not very clear on your explaination there.

If I use strstr(), do I still need to use regex methods like regcomp,
regexec?
 
A

Al Balmer

Not very clear on your explaination there.

If I use strstr(), do I still need to use regex methods like regcomp,
regexec?

Look up strstr() in your C book, or man page if you're on *nix. If you
don't figure it out, come back.
 
K

Keith Thompson

That's a literal string. Is it supposed to be an example of the
pattern you're searching for?
You will use the "strstr() " function for search the
pattern.Its syntax is
strstr(s,t)
-It search the pattern "t" in the
string "s".

strstr() searches for a string, not for a regular expression.
We have to include the user defined files ,then you create the file and
include like this
#include "regex.h".

strstr() is a standard function, declared in <string.h>.

"regex.h" is not defined by the C standard. If your system provides
it, it should also provide documentation. Failing that, try a
newsgroup for your system (comp.unix.programmer, maybe?).
 
C

cybernerdsx2

Yes, "v1.2.54" is what I want to check. I might also need to check
something like this "v3.2.T33" (notice the 'T' before 33).

I have looked into strstr() but it only allows passing in char* for
searching. But that does not help formy situation here.
 
V

Vladimir S. Oka

cybernerdsx2 said:
Hi,

I would like to use regex.h to search for a pattern like the following:

"v1.2.54"

how can I achieve that?

You'll have to ask somewhere where `regex.h` is known and topical. It
is not part of Standard C, so you're unlikely to get help here. Relpies
about `strstr()` are not going to be useful, unless you want to
implement regular expression searching yourself.
 
K

Keith Thompson

cybernerdsx2 said:
Yes, "v1.2.54" is what I want to check. I might also need to check
something like this "v3.2.T33" (notice the 'T' before 33).

I have looked into strstr() but it only allows passing in char* for
searching. But that does not help formy situation here.

Without context, it's difficult to tell what you're talking about.
Please read <http://cfaj.freeshell.org/google/>.

I don't understand why strstr() wouldn't serve your purpose. It
searches for a string in another string; the char* argument points to
the string.

You say that "v1.2.54" is what you want to check. Does that mean
you're looking specifically for "v1.2.54", not for "v1.2.55"?

What *exactly* are you trying to do? Showing some examples might be
helpful.
 
C

cybernerdsx2

okay, maybe i wasn't clear on this. When I say i want to check for
"v1.2.54" it is not fixed, meaning, my code needs to dynamically picks
up that I want to search for the version number on a application. That
application can changed to v1.3.4 and so on in the future.

So my program will have to pick up the pattern to check for that
version which will always be like this pattern : "vX.XX.AXXX" being X
as numeric and A as alphabet.

Hope this clears up the situation here?
 
K

Keith Thompson

cybernerdsx2 said:
okay, maybe i wasn't clear on this. When I say i want to check for
"v1.2.54" it is not fixed, meaning, my code needs to dynamically picks
up that I want to search for the version number on a application. That
application can changed to v1.3.4 and so on in the future.

So my program will have to pick up the pattern to check for that
version which will always be like this pattern : "vX.XX.AXXX" being X
as numeric and A as alphabet.

Hope this clears up the situation here?

You're still not providing context.

I already asked you to read <http://cfaj.freeshell.org/google/>.
Please do so now.

You might be able to use sscanf(); it doesn't support full regular
expressions, but it does let you search for simpler patterns.

But if you really want regular expressions, you'll have to use
facilities that are not provided by standard C. Either read your
system's documentation, or ask in a newsgroup appropriate to your
system. (Which is exactly what you've been told before.)
 
A

Al Balmer

okay, maybe i wasn't clear on this. When I say i want to check for
"v1.2.54" it is not fixed, meaning, my code needs to dynamically picks
up that I want to search for the version number on a application. That
application can changed to v1.3.4 and so on in the future.

So my program will have to pick up the pattern to check for that
version which will always be like this pattern : "vX.XX.AXXX" being X
as numeric and A as alphabet.

Hope this clears up the situation here?

Well, in a way, it does clear up the situation. It's becoming clear
that you have some very basic things to learn before writing a C
program.

Do you have any experience programming in any language? I would
suggest that you get a copy of Kernighan and Ritchie, "The C
Programming Language" and study it carefully. It's perhaps the best
tutorial around, but the writing is not verbose, and you have to pay
attention.
 

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,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top