Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regular expressions

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hi,

How do i write a regular expression in c# to extract a part of a string.

lets say i have a string

test = "CGDHTYJHJHGJUNK HERE:FGDGASPSESSIONID:IWANTTHISHERE;fgfghfghfgh"

I want to extract everything after ASPSESSIONID up until i get to the ;


thanks for your help
 
If you want to keep the colon ie:

:IWANTTHISHERE

use:

(?<=ASPSESSIONID).*(?=;)

If you want theresult to exclude the colon then use:

(?<=ASPSESSIONID:).*(?=;)


Hope this helps.
 
The regular expression returns a match collection - using vb.net syntax to return the actual matches:


Dim rx As New System.Text.RegularExpressions.Regex(TextBox2.Text)
For Each m As System.Text.RegularExpressions.Match In rx.Matches(TextBox1.Text)
MessageBox.Show(m.ToString)
Next

where TextBox2 contains the pattern as in my previous post and TextBox1 contains the string to match as in your original post.


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top