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. Regular Expressions

Regular Expressions

Scheduled Pinned Locked Moved C#
databasequestion
3 Posts 3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi if i have a string "a sheep jumped over the moon" how would i extract the word 'jumped' without using a for loop? I have herd that regular expressions would be able to do this. Would this also return the index of where the first character is also ? anyone? cheers

    J C 2 Replies Last reply
    0
    • L Lost User

      Hi if i have a string "a sheep jumped over the moon" how would i extract the word 'jumped' without using a for loop? I have herd that regular expressions would be able to do this. Would this also return the index of where the first character is also ? anyone? cheers

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Yes regular expressions (regex) will do that. My regex is very bad so I'll not attempt to show that but the form would be something like.

      Regex re = new Regex(myRegExpression);

      Match match = re.Match(myStringToSearch);

      System.Console.WriteLine("Match found at: " + match.Index);

      I think the RegExpression would be (.)*jumped(.)*, but as I said I'm not very good with them HTH, James Sonork ID: 100.11138 - Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

      1 Reply Last reply
      0
      • L Lost User

        Hi if i have a string "a sheep jumped over the moon" how would i extract the word 'jumped' without using a for loop? I have herd that regular expressions would be able to do this. Would this also return the index of where the first character is also ? anyone? cheers

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Just to clarfiy, you want to do a basic string search, which does not need RegEx. The point of a regular expression is that you can use wildcards, for example sh*p would find sheep, shlap any other combination that has an sh followed by any number of chars follwed by p. * would find anything and *.bmp would find all .bmp files. I don't remember any of the other wildcards off the top of my head :0) Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. "I'm somewhat suspicious of STL though. My (test,experimental) program worked first time. Whats that all about??!?! - Jon Hulatt, 22/3/2002

        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