Re: Getting certain text from textbox (not as simple)
Here's a regex for you:
Code:
@@([\S]+)+\ssends,\s"(.+)"
its first capturing group will correspond for name and the second one - the message
Now the grand question. What is regex?
RegEx comes from Regular Expressions - a very powerful tool for text search using fuzzy search criteria (like yours).
To learn more, you can visit this site: http://www.regular-expressions.info/
The basics about RegEx can be also read at wikipedia: http://en.wikipedia.org/wiki/Regular_expression
And finally, to use Regular Expressions in your VB application, you will need a VS.Net regex engine which is accessible through System.Text.RegularExpressions namespace.
Here you can find a complete syntax reference:
http://msdn.microsoft.com/en-us/libr...cs(VS.80).aspx
Re: Getting certain text from textbox (not as simple)
Quote:
Originally Posted by
cicatrix
Here's a regex for you:
Code:
@@([\S]+)+\ssends,\s"(.+)"
its first capturing group will correspond for name and the second one - the message
Now the grand question. What is regex?
RegEx comes from
Regular
Expressions - a very powerful tool for text search using fuzzy search criteria (like yours).
To learn more, you can visit this site:
http://www.regular-expressions.info/
The basics about RegEx can be also read at wikipedia:
http://en.wikipedia.org/wiki/Regular_expression
And finally, to use Regular Expressions in your VB application, you will need a VS.Net regex engine which is accessible through System.Text.RegularExpressions namespace.
Here you can find a complete syntax reference:
http://msdn.microsoft.com/en-us/libr...cs(VS.80).aspx
Ty for reply, is there another way?
For one it looks very hard to learn, also the expression you gave me doesn't seem to work when I actually tried it.
Re: Getting certain text from textbox (not as simple)
The pattern given by cicatrix worked perfect when I tried it. Here's a function (that assumes you have imported the System.Text.RegularExpression namespace) that will return a List(Of String) where each string looks as follows (without the quotes) "name: message". You should easily be able to change that into any kind of output.
Code:
Private Function GetConversation(ByVal text As String) As List(Of String)
Dim regex As New Regex("@@([\S]+)+\ssends,\s""(.+)""")
Dim matches = regex.Matches(text)
Dim list As New List(Of String)
For Each m As Match In matches
list.Add(m.Groups(1).Value & ": " & m.Groups(2).Value)
Next
Return list
End Function
1 Attachment(s)
Re: Getting certain text from textbox (not as simple)
The regex works fine. I prepared a sample project with this expression (VS2010)
I used a listview to display the results.
The code itself is very simple:
vb Code:
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub txtInput_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInput.TextChanged
Dim pattern = "@@([\S]+)+\ssends,\s""(.+)"""
For Each m As Match In Regex.Matches(txtInput.Text, pattern)
Dim nme As String = m.Groups(1).Value
Dim msg As String = m.Groups(2).Value
Dim lvi As New ListViewItem(nme)
lvi.SubItems.Add(msg)
lvNames.Items.Add(lvi)
Next
End Sub
End Class
Just paste your log into the left textbox (txtInput) and see the results in the listview.