By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,655 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,655 IT Pros & Developers. It's quick & easy.

Regular expression for numeric

P: n/a
Hi,

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

"v1.2.54"

how can I achieve that?

Apr 21 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a

cybernerdsx2 wrote:
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.

Apr 21 '06 #2

P: n/a
Not very clear on your explaination there.

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

Apr 21 '06 #3

P: n/a
On 20 Apr 2006 21:16:09 -0700, "cybernerdsx2" <fo*********@gmail.com>
wrote:
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.

--
Al Balmer
Sun City, AZ
Apr 21 '06 #4

P: n/a
"balasam" <bk*****@gmail.com> writes:
cybernerdsx2 wrote:
I would like to use regex.h to search for a pattern like the following:

"v1.2.54"

how can I achieve that?

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?).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 21 '06 #5

P: n/a
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.

Apr 21 '06 #6

P: n/a

cybernerdsx2 wrote:
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.

Apr 21 '06 #7

P: n/a
"cybernerdsx2" <fo*********@gmail.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 21 '06 #8

P: n/a
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?

Apr 21 '06 #9

P: n/a
"cybernerdsx2" <fo*********@gmail.com> writes:
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.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 21 '06 #10

P: n/a
On 21 Apr 2006 02:05:49 -0700, "cybernerdsx2" <fo*********@gmail.com>
wrote:
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.

--
Al Balmer
Sun City, AZ
Apr 21 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.