By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,105 Members | 2,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,105 IT Pros & Developers. It's quick & easy.

How to parse for a substring using regular expressions??

P: n/a
Hi,

does anybody know I can extract a substring of a text with regular expressions. Let’s consider the following text: “Regular expressions are often used to make sure that a string matches a certain pattern.”.

I e.g. want to extract everything between “expressions” and “a” which is in the above example “are often used to make sure that”.

The unfortunately best I could do was the following piece of code:

Dim myRegularExpression As New System.Text.RegularExpressions.Regex("expressions[\s\S]*\sa\s")

myMatch = myRegularExpression.Match("Regular expressions are often used to make sure that a string matches a certain pattern.")

Console.WriteLine(myMatch.Value)

which lead to the following result:
"expressions are often used to make sure that a string matches a "

Unfortunately my RegEx takes the last “a” in the text string but I want it to recognize the first appearance of “a”.

Does anybody have a clever idea?

Thank you!
Daniel Walzenbach

Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Daniel,

Thanks for posting in the community.

I noticed you have posted a same problem in the
microsoft.public.dotnet.framework queue, and one community member posted a
reply to you in that queue.
Please review it in that queue.
Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.