PDA

View Full Version : Regular Expression for a text file



msampath
05-19-2014, 11:55 PM
Hello all,

I am having a text file with the following data.


d:\Sandbox\BMW35UP_Testview_I320\MainMicro\Application\Abs\Abs_Main\DOCS\Pu blic\TrimInfo\Canape\project.pj
d:\Sandbox\BMW35UP_Testview_I320\MainMicro\Application\Abs\Abs_Main\SOURCE\ project.pj
/SCS/SCS_Core_Based/08_Software/Application/ABS/ABS_GEN1/MAIN/APPLICATION/SOURCE/abs.h 1.9.1.1 d:\Sandbox\BMW35UP_Testview_I320\MainMicro\Application\Abs\Abs_Main\SOURCE\ abs.h
/SCS/SCS_Core_Based/08_Software/Application/ABS/ABS_GEN1/MAIN/APPLICATION/SOURCE/abs_calibration_database_sub.h 1.3.2.1 d:\Sandbox\BMW35UP_Testview_I320\MainMicro\Application\Abs\Abs_Main\SOURCE\ abs_calibration_database_sub.h
/SCS/SCS_Core_Based/08_Software/Application/ABS/ABS_GEN1/MAIN/APPLICATION/SOURCE/abs_conditional_switches.h 1.8.1.1 d:\Sandbox\BMW35UP_Testview_I320\MainMicro\Application\Abs\Abs_Main\SOURCE\ abs_conditional_switches.h


i want to implement regular expression for all the lines in a file

Regex pattern ="^ .*\n" and replace width =""


kindly help me in this regard..

Thanks & Regards,
Sampath

EirikDaude
05-20-2014, 01:05 AM
I copied this example from Microsoft's help pages for Regex.Replace (http://msdn.microsoft.com/en-us/library/xwewhkd1%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1):

Imports System.Text.RegularExpressions

Module Example
Public Sub Main()
Dim pattern As String = "(\p{Sc}\s?)?(\d+\.?((?<=\.)\d+)?)(?(1)|\s?\p{Sc})?"
Dim input As String = "$17.43 €2 16.33 £0.98 0.43 £43 12€ 17"
Dim replacement As String = "$2"
Dim rgx As New Regex(pattern)
Dim result As String = rgx.Replace(input, replacement)

Console.WriteLine("Original String: '{0}'", input)
Console.WriteLine("Replacement String: '{0}'", result)
End Sub
End Module
' The example displays the following output:
' Original String: '$17.43 €2 16.33 £0.98 0.43 £43 12€ 17'
' Replacement String: '17.43 2 16.33 0.98 0.43 43 12 17'
Is that more or less what you are looking for?