正则表达式模式 [英] Regex pattern
问题描述
我的文本文件中有这样的行 Page 10 I have lines like this in my text file Page 10 ---- -------------------------------------------------- ------------------------ ------------------------------------------------------------------------------ AGILENT 3070 FIXTURE WIRING REPORT Sun Apr 19,2009 12:47:44 PM AGILENT 3070 FIXTURE WIRING REPORT Sun Apr 19, 2009 12:47:44 PM / var / hp3070 / boards / Celestica / 11_CFDIU / fixture / wires /var/hp3070/boards/Celestica/11_CFDIU/fixture/wires ------------- -------------------------------------------------- --------------- ------------------------------------------------------------------------------ |来自|到|来自|至 | From | To | From | To 长度| Ga |颜色|(b r c)|(b r c)| X Y | XY Length|Ga|Color |(b r c )|(b r c )| X Y | X Y ------ | - | ------ | --------------- | ----- ---------- | ------- | ------- | ------- | ------- ------|--|------|---------------|---------------|-------|-------|-------|------- 1.0 28蓝色(2 11.50 35.0)[T18] 84111 -8225 117.78 107.62 1.0 28 Blue (2 11.50 35.0) [T18 ] 84111 -8225 117.78 107.62 1.0 28蓝色(2 11.50 34.0)[T84] 85611 -8225 85111 -6225 1.0 28 Blue (2 11.50 34.0) [T84 ] 85611 -8225 85111 -6225 1.0 28蓝色(2 11.50 30.0)[T85] 91611 -8225 85111 -4725 1.0 28 Blue (2 11.50 30.0) [T85 ] 91611 -8225 85111 -4725 1.0 28蓝色(2 11.50 33.0)[T176] 87111 -8225 79111 -13725 1.0 28 Blue (2 11.50 33.0) [T176 ] 87111 -8225 79111 -13725 1.0 28蓝色(2 11.14 11.0)[2 10.99 11.0] 120111 -10758 120104 -11791 1.0 28 Blue (2 11.14 11.0) [2 10.99 11.0] 120111 -10758 120104 -11791 1.0 28蓝色(2 11.57) 10.0)[2 11.98 05.4] 121611 -7719 128446 -4880 1.0 28 Blue (2 11.57 10.0) [2 11.98 05.4] 121611 -7719 128446 -4880 1.0 28蓝色(2 11.00 08.0)[2 11.12 07.6] 124611 -11725 125178 -10864 1.0 28 Blue (2 11.00 08.0) [2 11.12 07.6] 124611 -11725 125178 -10864 1.0 28蓝色(2 11.00 09.0)[2 10.84 05.4] 123111 -11725 128446 -12872 1.0 28 Blue (2 11.00 09.0) [2 10.84 05.4] 123111 -11725 128446 -12872 1.0 28蓝色(2 10.00 09.0)[2 10.98 05.4] 123111 -18725 128446 -11849 1.0 28 Blue (2 10.00 09.0) [2 10.98 05.4] 123111 -18725 128446 -11849 1.0 28蓝色(2 10.50 10.0)[2 10.03 10.4] 121611 -15225 120966 -18502 1.0 28 Blue (2 10.50 10.0) [2 10.03 10.4] 121611 -15225 120966 -18502 1.0 28蓝色(2 11.00) 34.0)[T175] 85611 -11725 83611 -13725 1.0 28 Blue (2 11.00 34.0) [T175 ] 85611 -11725 83611 -13725 1.0 28蓝色(2 10.00 36.0)[T94] 82611 -187 25 82111 -16725 1.0 28 Blue (2 10.00 36.0) [T94 ] 82611 -18725 82111 -16725 返回 修剪(matchColl(0).Value.ToString()) Return Trim(matchColl(0).Value.ToString()) 任何人都可以帮助我显示错误的原因。 Dim patternStr 作为 < span style ="font-size:x-small"> Dim patternStr As String = "\[([\bT]|\s|\.)+\]" 有人可以帮我解决这个问题吗?谢谢 Can some one help me to solve this problem? Thank you 这篇关于正则表达式模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
我想按加号顺序对包含[T ....]的行进行排序,并将其放在法线下面。我正在使用TComparer方法。这是我到目前为止
I want to sort the lines which contain [T....] in accending order and put below the normal lines. Im using TComparer methode. This is my so farTcomparer.Vb
Imports System.Text
Imports System.Collections
Public Class TComparer
Implements IComparer
Public Function ComareTo(ByVal obj1 As Object, ByVal obj2 As Object) As Integer Implements IComparer.Compare
Dim o1 As Object = CType(obj1, Object)
Dim o2 As Object = CType(obj2, Object)
Return String.Compare(get_tees(o1), get_tees(o2))
End Function
Public Function get_tees(ByVal inputstr As String) As String
Dim patternStr As String = "\[([\bT]|\s|\.)+\]"
Dim regexObj As New RegularExpressions.Regex(patternStr)
Dim matchColl As RegularExpressions.MatchCollection
matchColl = regexObj.Matches(inputstr)
Return Trim(matchColl(0).Value.ToString())
End Function
End Class
This is code in button click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strArr() As String = System.IO.File.ReadAllLines(strFileName)
Dim sf As StreamWriter = File.CreateText(strFileName)
Dim sortingbyT As TComparer = New TComparer
Array.Sort(strArr, sortingbyT)
For Each item As String In strArr
sf.WriteLine("{0}", item)
Next
Console.Read()
End Sub
End Class
This is code in button click
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strArr() As String = System.IO.File.ReadAllLines(strFileName)
Dim sf As StreamWriter = File.CreateText(strFileName)
Dim sortingbyT As TComparer = New TComparer
Array.Sort(strArr, sortingbyT)
For Each item As String In strArr
sf.WriteLine("{0}", item)
Next
Console.Read()
End Sub
End Class
But it shows this error "Specified argument was out of the range of valid values. Parameter name: i" at this line
我认为我的正则表达式模式不正确就是这行
Can any one help me why it shows the error.
I think my regex pattern is not correct which is this line String
推荐答案
[T1],[T2]的正确的正则表达式模式是什么..... [T89]
我这样用过。 " \ [([\ bT] | \s | \。)+ \]"这是正确的 What is correct regex pattern for [T1 ] , [T2 ].....[T89 ]
I used like this. "\[([\bT]|\s|\.)+\]" is this correct