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