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#
  4. Generating strings that are matched by a regex

Generating strings that are matched by a regex

Scheduled Pinned Locked Moved C#
csharpalgorithmsregexquestionlounge
4 Posts 3 Posters 1 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.
  • B Offline
    B Offline
    bnieland
    wrote on last edited by
    #1

    Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent

    K L 2 Replies Last reply
    0
    • B bnieland

      Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent

      K Offline
      K Offline
      Kentamanos
      wrote on last edited by
      #2

      It's obviously pretty easy to code one for each individual regular expression by hand, but something that generates a random string for ANY given regular expression seems like it would be fairly complicated. I'm pretty sure there's nothing in the base classes for this. It would definitely have to understand the regular expression syntax you're using. How would you handle something like: [a-z]* That means zero to "infinite" lower case letters basically. Would your random generator have an upper limit on cases like that? Would you want zero's to occur more often than other numbers? I wish I could help more, but I've never heard of anyone doing this (haven't really searched or anything though). Let me know how it turns out.


      I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
      -David St. Hubbins

      1 Reply Last reply
      0
      • B bnieland

        Folks, For bizarre reasons, I need to be able to generate random strings that will be matched by a given regex. i.e. given [a-z][a-z1-9][qrst] I want an algorithm that will generate abs z9q dvt et cetera... Anyone hear of anything similar? Or maybe you know a simple regex parser that I cannibalize? (C# preferable, or a C related language) Thanks, Brett DTrent

        L Offline
        L Offline
        leppie
        wrote on last edited by
        #3

        I have a simple C# Regex lib designed for a lexer, rather than normal RE. I'll send you the code and if you can use it, i would dearly love to have it :) Obviously you would be credited (just place a gpl on your source). Reply to this message so I grab your email :) leppie::AllocCPArticle("Zee blog");
        Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

        B 1 Reply Last reply
        0
        • L leppie

          I have a simple C# Regex lib designed for a lexer, rather than normal RE. I'll send you the code and if you can use it, i would dearly love to have it :) Obviously you would be credited (just place a gpl on your source). Reply to this message so I grab your email :) leppie::AllocCPArticle("Zee blog");
          Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.

          B Offline
          B Offline
          bnieland
          wrote on last edited by
          #4

          Thanks, That might help a lot! DTrent

          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