How to extract part of the text from the line with a special format

Mansour_Dalir 1,696 Reputation points
2024-05-13T02:00:27.6033333+00:00

hi

Bolded areas need to be extracted. I don't know how to use Regex library.

my Format [One of the tags] is Sample '10LBA04CT004-XQ01'

Start text with 150,000 lines and have different tags. thank

{

N 3-SH 3-sh 3-sh 3-SH N

10LBB09

EQUIPMENT = 10LBA01GF002

10LBA01GF002

N 1 1-BLACK 10LBA04CT004-XQ01 1-BLACK 1 10LBA04 N

N 2 1-L.BLUE 10LBA04CT004-XQ01 1-L.BLUE 2 10LBA04 N

N 1-SH 1-SH 1-SH 1-SH N

N 3 2-BLACK 10LBA04CT005-XQ01A 2-BLACK 3 10LBA04 N

N 4 2-L.BLUE 10LBA04CT005-XQ01B 2-L.BLUE 4 10LBA04 N

N 4 2-L.BLUE 10LBA04CT05-XQ01B 2-L.BLUE 4 10LBA04 N

}

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,855 questions
Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,688 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,602 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 27,241 Reputation points Microsoft Vendor
    2024-05-13T03:49:22.53+00:00

    Hi @Mansour_Dalir ,

    You can use regular expressions to match the text in the specific format you need.

    Modify the regular expression according to the format you need.

            Dim pattern As String = "\b[1][0][L][B]+\w*[-XQ]+\w*\b"
            Dim input As String = "N 3-SH 3-sh 3-sh 3-SH N
    
    10LBB09
    
    EQUIPMENT = 10LBA01GF002
    
    10LBA01GF002
    
    N 1 1-BLACK 10LBA04CT004-XQ01 1-BLACK 1 10LBA04 N
    
    N 2 1-L.BLUE 10LBA04CT004-XQ01 1-L.BLUE 2 10LBA04 N
    
    N 1-SH 1-SH 1-SH 1-SH N
    
    N 3 2-BLACK 10LBA04CT005-XQ01A 2-BLACK 3 10LBA04 N
    
    N 4 2-L.BLUE 10LBA04CT005-XQ01B 2-L.BLUE 4 10LBA04 N
    
    N 4 2-L.BLUE 10LBA04CT05-XQ01B 2-L.BLUE 4 10LBA04 N"
            Dim matches As MatchCollection = Regex.Matches(input, pattern)
    
            For Each m As Match In matches
                Console.WriteLine(m.Value)
            Next
    
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful