Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:46:09+00:00 2026-06-07T14:46:09+00:00

I created a list from a subtitle file (.srt) in which every line is

  • 0

I created a list from a subtitle file (.srt) in which every line is inside a index of the list. Now I want to erase some lines, specially lines starting with the time interval in the format “xx:xx:xx,xxx –> xx:xx:xx,xxx”. I did some research (ok, quite superficial research on a complex topic, I might add) and tried to create the following sub:

Private Shared Sub listCleaning(ByRef sList As List(Of String))
    For Each line As String In sList
        Dim pattern As String = "\b\d\d:\d\d:\d\d:\d\d,\d\d\d --> \b\d\d:\d\d:\d\d:\d\d,\d\d\d"
        Dim reg As New Regex(pattern)

        If line = "" Or Integer.TryParse(line, Nothing) Or reg.IsMatch(pattern) Then
            sList.Remove(line)
        End If
    Next
End Sub

Now Im having two problems:

  1. My Regular Expression is not beeing correctly parsed.
  2. When I have a valid condition on my If Block and the line gets removed, I have a InvalidOperationException when hiting next since the list has changed.

Can anyone help me to write a correct RegEx and a way to iterate through the list removing the unwanted lines?

tnx in advance.

EDIT:

Ok, Tim got most of the problem out but I still need a RegEx that suits the pattern “xx:xx:xx,xxx –> xx:xx:xx,xxx”. Anyone willing to care?

thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:46:16+00:00Added an answer on June 7, 2026 at 2:46 pm

    These are my changes to your original code.

    First, I don’t use the for each loop, but the more traditional for loop
    Second, Loop in reverse, so your delete goes to the end of the list
    Third, the regex pattern should be outside the loop

    Private Shared Sub listCleaning(ByRef sList As List(Of String)) 
        Dim pattern As String = "\d{2}:\d{2}:\d{2},\d{3}\s+-->\s+\d{2}:\d{2}:\d{2},\d{3}" 
        Dim reg As New Regex(pattern) 
        Dim x as Integer
        For x = sList.Count - 1 to 0 step -1
            Dim line as string = sList(x)
                    Console.WriteLine(line)
            If line = "" Or Integer.TryParse(line, Nothing) Or reg.IsMatch(line) Then 
                   sList.Remove(line) 
            End If 
        Next 
    End Sub 
    

    This is my test data:

    Sub Main
        Dim sList as List(Of String) = new List(Of string)
        sList.Add("01:01:01,003 --> 02:02:02,003")
        sList.Add("sdsdfsdfsd03 --> 02:02:02,003")
        sList.Add("03:01:01,003 --> 03:02:02,003")
        sList.Add("04:01:01,003 --> 04:02:02,003")
        sList.Add("05:01:01,003 --> 05:02:02,003")
        sList.Add("06:01:01,003 --> 06:02:02,003")
        sList.Add("07:01:01,003 --> 07:02:02,003")
        sList.Add("08:01:01,003 --> 08:02:02,003")
        sList.Add("09:01:01,003 --> 02:02:02 003")    
    
        console.WriteLine("Call listCleaning with " + sList.Count.ToString +  " elements")
    
        listCleaning(sList)
    
        console.WriteLine("Returned with " + sList.Count.ToString +  " elements")
        for each line as String in sList
            Console.WriteLine(line)
        next
    End Sub
    

    To get this output

    Call listCleaning with 9 elements
    09:01:01,003 --> 02:02:02 003
    08:01:01,003 --> 02:02:02,003
    07:01:01,003 --> 02:02:02,003
    06:AA:01,003   --> 02:02:02,003
    05:01:01,003 -->    02:02:02,003
    04:01:01,003 --> 02:02:02,003
    03:01:01,003 --> 02:02:02,003
    sdsdfsdfsd03 --> 02:02:02,003
    01:01:01,003 --> 02:02:02,003
    Returned with 3 elements
    sdsdfsdfsd03 --> 02:02:02,003
    06:AA:01,003   --> 02:02:02,003
    09:01:01,003 --> 02:02:02 003
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've created list in first layout from server, and now i want to go
I am creating a CSV from a list of values. CSV File gets created
I have created an array list from a database column and I want to
I have a dynamically created list. Items from the list should be able to
I have already created a webpart to show the data from list, but I
I've created a listview that's filled up with a list of guitars from the
I have a list of items that are created from the results of website
I have created an editor template for representing selecting from a dynamic dropdown list
I`v come across a need where I want to create multiple list items from
I've created a list from table records and i added a rightclick event for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.