|
-
Jan 29th, 2011, 04:17 AM
#5
Fanatic Member
Re: Regex to get string.
 Originally Posted by dynamic_sysop
because the pStyle varies, you would need to make a new regex pattern for each line with that code.
you could do this also, which would avoid the pStyle issue...
Code:
'/// this pattern will search for the { and the stuff between and the }
Dim strPattern As String = Regex.Escape("{") & "(.*)}"
Dim strToSearch As String = "#pStyle03X0 {XXX: 0px;YYYY: 144px;xxxxx:XXXXX: 1000;xxxxx: 498.00; xxxxx:714.00; }"
Dim rgx As New Regex(strPattern, RegexOptions.IgnoreCase)
Dim strResult As String = String.Empty
'/// this will trim the {} off each match as it's found...
Dim charsToTrim As Char() = {"{", "}"}
Dim rgxMatches As MatchCollection = rgx.Matches(strToSearch)
For Each m As Match In rgxMatches
strResult &= m.Value.Trim(charsToTrim) & Environment.NewLine
Next
MessageBox.Show(strResult)
He said he wanted the contents of "#pStyle03X1", not the contents of all of them. I answered his specific question. If you wanted to capture them all:
vb Code:
Dim mCollect As MatchCollection = Regex.Matches("inputstr", "(?<=#pStyle\w*\s{).*?(?=})", RegexOptions.IgnoreCase)
For each m As Match in mCollect
MsgBox(m.Value)
Next
If I helped you out, please take the time to rate me 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|