Regular expression for numeric

Discussion in 'C Programming' started by cybernerdsx2, Apr 21, 2006.

  1. cybernerdsx2

    cybernerdsx2 Guest

    Hi,

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

    "v1.2.54"

    how can I achieve that?
     
    cybernerdsx2, Apr 21, 2006
    #1
    1. Advertising

  2. cybernerdsx2

    balasam Guest

    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.
     
    balasam, Apr 21, 2006
    #2
    1. Advertising

  3. cybernerdsx2

    cybernerdsx2 Guest

    Not very clear on your explaination there.

    If I use strstr(), do I still need to use regex methods like regcomp,
    regexec?
     
    cybernerdsx2, Apr 21, 2006
    #3
  4. cybernerdsx2

    Al Balmer Guest

    On 20 Apr 2006 21:16:09 -0700, "cybernerdsx2" <>
    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
     
    Al Balmer, Apr 21, 2006
    #4
  5. "balasam" <> 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) <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.
     
    Keith Thompson, Apr 21, 2006
    #5
  6. cybernerdsx2

    cybernerdsx2 Guest

    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.
     
    cybernerdsx2, Apr 21, 2006
    #6
  7. 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.
     
    Vladimir S. Oka, Apr 21, 2006
    #7
  8. "cybernerdsx2" <> 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) <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.
     
    Keith Thompson, Apr 21, 2006
    #8
  9. cybernerdsx2

    cybernerdsx2 Guest

    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?
     
    cybernerdsx2, Apr 21, 2006
    #9
  10. "cybernerdsx2" <> 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) <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.
     
    Keith Thompson, Apr 21, 2006
    #10
  11. cybernerdsx2

    Al Balmer Guest

    On 21 Apr 2006 02:05:49 -0700, "cybernerdsx2" <>
    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
     
    Al Balmer, Apr 21, 2006
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,400
  2. Replies:
    3
    Views:
    404
    Andrew Thompson
    Jan 26, 2007
  3. Replies:
    5
    Views:
    985
    X-Centric
    Jun 30, 2005
  4. darrel
    Replies:
    4
    Views:
    870
    darrel
    Jul 19, 2007
  5. .Net Sports
    Replies:
    7
    Views:
    232
    shimmyshack
    Apr 19, 2007
Loading...

Share This Page