Regular Expression help, getting the last data not the ones b4 that

XtremeMaC

Member
Joined
Oct 22, 2007
Messages
8
Location
Turkey
Programming Experience
3-5
Hi there
i'm trying to copy the text from the clipboard. the clipboard could be a url or just a sentence with comma & dots etc..

i'd like to strip out the [tabs, white spaces, returns, new lines] from the beginning of a word and I don't want to those stuff after the last word or beginning of a new line as well.

example:
space space space tab new line
new line
tab space space
sentence 1tab, new line new line
tab space sentence 2

so i want to strip out from the beginings and at the ends

so above text will be like
sentence 1 new line
sentence 2


i wrote some really crazy stupid reg ex like this: (?:\s.\t.\n.\r.(?<1>[*].)|(?<1>\S+))

and i can only get the last word of sentence 2

surely i'm new to reg ex :)

please help
 
Not regex, but it returns the string you asked for:
VB.NET:
Function getSentences(ByVal s As String) As String
    Dim sep As String = vbTab & vbNewLine
    Dim lines() As String = s.Split(sep.ToCharArray, StringSplitOptions.RemoveEmptyEntries)
    Dim sentences As New List(Of String)
    For Each line As String In lines
        line = line.Trim
        If line <> "" Then sentences.Add(line)
    Next
    Return String.Join(vbNewLine, sentences.ToArray)
End Function
 
Back
Top