|
-
Sep 22nd, 2003, 03:12 AM
#1
Thread Starter
Frenzied Member
Regular Expressions [resolved]
I am trying to learn regular expressions and I have the basics down, but it is a pain. I am trying to parse the code that forums like this use: ie [b ]bold stuff[/b ], but I am having trouble if they go over multiple lines.
Code:
Dim linksExpression As Regex
Dim strPattern As String = "\[B ](.+?)\[/B ]"
linksExpression = New Regex(strPattern, RegexOptions.Multiline Or RegexOptions.IgnoreCase)
strTemp = linksExpression.Replace(strTemp, "<b>$1</b>")
this works fine if I have it all on one line like [b ]bold stuff[/b ], but if I do
[b ]bold
stuff[/b ], it doesn't work.
Last edited by blindlizard; Sep 23rd, 2003 at 02:51 PM.
-
Sep 22nd, 2003, 03:24 AM
#2
Try removing the RegexOptions.Multiline option. That will process each line individually instead of all of the string as one.
-
Sep 22nd, 2003, 03:25 AM
#3
Thread Starter
Frenzied Member
Tried that, same thing happens.
-
Sep 22nd, 2003, 03:26 AM
#4
Post some sample text to test on and i'll take a gander at it.
-
Sep 22nd, 2003, 03:30 AM
#5
Thread Starter
Frenzied Member
Code:
Dim linksExpression As Regex
Dim strPattern As String = "\[B ](.+?)\[/B ]"
strTemp = "[B ]bold" & vbCrLf & "this[/B ]"
linksExpression = New Regex(strPattern, RegexOptions.IgnoreCase)
strTemp = linksExpression.Replace(strTemp, "<b>$1</b>")
'strTemp returns what was sent in
Dim linksExpression As Regex
Dim strPattern As String = "\[B ](.+?)\[/B ]"
strTemp = "[B ]bold" & vbCrLf & "this[/B ]"
linksExpression = New Regex(strPattern, RegexOptions.IgnoreCase)
strTemp = linksExpression.Replace(strTemp, "<b>$1</b>")
'strTemp returns <b>bold this</b>
-
Sep 22nd, 2003, 03:31 AM
#6
Thread Starter
Frenzied Member
I am thinking that I may have to remove the vbCrlf and put in something like <br> and then put it back to VbCrlf at the end.
-
Sep 22nd, 2003, 03:43 AM
#7
You have to use the SingleLine option:
VB Code:
Dim strPattern As String = "\[B ](.*)\[/B ]"
Dim linksExpression As New Regex(strPattern, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
Dim strTemp As String = "[B ]bold" & vbCrLf & "this[/B ]"
strTemp = linksExpression.Replace(strTemp, "<b>$1</b>")
MsgBox(strTemp)
-
Sep 22nd, 2003, 03:45 AM
#8
Thread Starter
Frenzied Member
Thanks man! I would never have found that. Documentation on the web is crap for regular expressions in .Net
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
|