Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Regular expression

Regular expression

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++databaseregexhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Demian Panello
    wrote on last edited by
    #1

    Hi. I need to generate a regular expression. I use to do this by hand, in cases like the following: I have: 340000000000000 349999999999999 and 370000000000000 379999999999999 they represents ranges, then I store in a database the following regular expresion: 3[4,7]% That's easy. But there are cases like: 6221260000000000 6229259999999999 that it's not so simple, but I used to solve that, (in this case with a few of regular expresions similar like the one above), but my head start to hurts. :doh: And, you know, there are another ranges that need very complex regular expressions. So, my question is: Somebody knows about a tool, or program (or maybe a class that I could use in my program) that it could help me to build regular expressions like the ones above, just with the input of that ranges? Or maybe someone have some useful ideas about it. I know, maybe this is not the right forum to post that, but I thought, just because I'm using C++... Any help or hint will be appreciate it. Thanks.

    Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

    B 1 Reply Last reply
    0
    • D Demian Panello

      Hi. I need to generate a regular expression. I use to do this by hand, in cases like the following: I have: 340000000000000 349999999999999 and 370000000000000 379999999999999 they represents ranges, then I store in a database the following regular expresion: 3[4,7]% That's easy. But there are cases like: 6221260000000000 6229259999999999 that it's not so simple, but I used to solve that, (in this case with a few of regular expresions similar like the one above), but my head start to hurts. :doh: And, you know, there are another ranges that need very complex regular expressions. So, my question is: Somebody knows about a tool, or program (or maybe a class that I could use in my program) that it could help me to build regular expressions like the ones above, just with the input of that ranges? Or maybe someone have some useful ideas about it. I know, maybe this is not the right forum to post that, but I thought, just because I'm using C++... Any help or hint will be appreciate it. Thanks.

      Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

      B Offline
      B Offline
      BobInNJ
      wrote on last edited by
      #2

      First, realize that not all sets of numbers can be represented by regular expressions. For example, the set of all prime integers cannot be represented as a regular expression. Now, one way to represent the set of real numbers between 143 and 163 is as follows: 143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163 The problem is with this approach is that the range of numbers may be quite large and the corresponding regular expression excessively large. Here is another regular expression that is smaller for the same range: 143|144|145|146|147|148|149|15(0|1|2|3|4|5|6|7|8|9)|160|161|162|163 I am thinking with this as a start, you can develop an algorithm for an arbitrary range and the regular expression is not going to be so big as to be unmanageable. I hope I helped you and feel free to ask a follow up question. Bob

      D 1 Reply Last reply
      0
      • B BobInNJ

        First, realize that not all sets of numbers can be represented by regular expressions. For example, the set of all prime integers cannot be represented as a regular expression. Now, one way to represent the set of real numbers between 143 and 163 is as follows: 143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163 The problem is with this approach is that the range of numbers may be quite large and the corresponding regular expression excessively large. Here is another regular expression that is smaller for the same range: 143|144|145|146|147|148|149|15(0|1|2|3|4|5|6|7|8|9)|160|161|162|163 I am thinking with this as a start, you can develop an algorithm for an arbitrary range and the regular expression is not going to be so big as to be unmanageable. I hope I helped you and feel free to ask a follow up question. Bob

        D Offline
        D Offline
        Demian Panello
        wrote on last edited by
        #3

        Thanks Bob. Well, that kind of stuff that you mention is what I used to do for every range, and there is always a solution. But, I just wonder if already exist a general way to solve this kind of problems. I'm thinking to write a program (maybe in C++ or C#) that help me in my job to proccess these ranges. Something like you enter a range of long numbers and then the programa list you all the regular expressions that help you to locate a value within that range. Thank you very much for your help.

        Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups