I need help in Regular Expressions Pattern
I need help in Regular Expressions Pattern
(OP)
Hi
I have a text file as the following and
I need the following regex maches (the match example is for the first line
but all the lines are the same)
I use the RegexOptions.Multiline
Can someone help me on the pattern to use
==============================
1
-.479 (12.17)
+.279 (7.09)
65
+.000 (0.00)
-.047 (1.19)
==============================
CODE -->
1 -.479 (12.17) +.279 (7.09) 65 +.000 (0.00) -.047 (1.19) 2 -.520 (13.21) +.190 (4.83) 66 +.000 (0.00) -.142 (3.61) 3 -.546 (13.87) +.095 (2.41) 67 +.000 (0.00) -.237 (6.02) 4 -.555 (14.10) +.000 (0.00) 68 +.000 (0.00) -.332 (8.43) 5 -.546 (13.87) -.095 (2.41) 69 +.000 (0.00) -.427 (10.85) 6 -.520 (13.21) -.190 (4.83) 70 +.000 (0.00) -.555 (14.10) 7 -.479 (12.17) -.279 (7.09) 71 +.083 (2.11) +.475 (12.07) 8 -.424 (10.77) +.357 (9.07) 72 +.083 (2.11) +.380 (9.65) 9 -.415 (10.54) +.190 (4.83) 73 +.083 (2.11) +.285 (7.24) 10 -.415 (10.54) +.095 (2.41) 74 +.083 (2.11) +.190 (4.83) 11 -.415 (10.54) .000 (0.00) 75 +.083 (2.11) +.095 (2.41) 12 -.415 (10.54) -.095 (2.41) 76 +.083 (2.11) +.000 (0.00) 13 -.415 (10.54) -.190 (4.83) 77 +.083 (2.11) -.095 (2.41) 14 -.424 (10.77) -.357 (9.07) 78 +.083 (2.11) -.190 (4.83) 15 -.332 (8.43) +.444 (11.28) 79 +.083 (2.11) -.285 (7.24) 16 -.332 (8.43) +.332 (8.43) 80 +.083 (2.11) -.380 (9.65) 17 -.332 (8.43) +.237 (6.02) 81 +.083 (2.11) -.475 (12.07) 18 -.332 (8.43) +.142 (3.61) 82 +.160 (4.06) +.531 (13.49) 19 -.332 (8.43) +.047 (1.19) 83 +.166 (4.22) +.427 (10.85) 20 -.332 (8.43) -.047 (1.19) 84 +.166 (4.22) +.332 (8.43) 21 -.332 (8.43) -.142 (3.61) 85 +.166 (4.22) +.237 (6.02) 22 -.332 (8.43) -.237 (6.02) 86 +.166 (4.22) +.142 (3.61) 23 -.332 (8.43) -.332 (8.43) 87 +.166 (4.22) +.047 (1.19) 24 -.332 (8.43) -.427 (10.85) 88 +.166 (4.22) -.047 (1.19) 25 -.249 (6.32) +.496 (12.60) 89 +.166 (4.22) -.142 (3.61) 26 -.249 (6.32) +.380 (9.65) 90 +.166 (4.22) -.237 (6.02) 27 -.249 (6.32) +.285 (7.24) 91 +.166 (4.22) -.332 (8.43) 28 -.249 (6.32) +.190 (4.83) 92 +.166 (4.22) -.427 (10.85) 29 -.249 (6.32) +.095 (2.41) 93 +.166 (4.22) -.522 (13.26) 30 -.249 (6.32) +.000 (0.00) 94 +.249 (6.32) +.496 (12.60) 31 -.249 (6.32) -.095 (2.41) 95 +.249 (6.32) +.380 (9.65) 32 -.249 (6.32) -.190 (4.83) 96 +.249 (6.32) +.285 (7.24) 33 -.249 (6.32) -.285 (7.24) 97 +.249 (6.32) +.190 (4.83) 34 -.249 (6.32) -.380 (9.65) 98 +.249 (6.32) +.095 (2.41) 35 -.249 (6.32) -.475 (12.07) 99 +.249 (6.32) +.000 (0.00) 36 -.160 (4.06) +.531 (13.49) 100 +.249 (6.32) -.095 (2.41) 37 -.166 (4.22) +.427 (10.85) 101 +.249 (6.32) -.190 (4.83) 38 -.166 (4.22) +.332 (8.43) 102 +.249 (6.32) -.285 (7.24) 39 -.166 (4.22) +.237 (6.02) 103 +.249 (6.32) -.380 (9.65) 40 -.166 (4.22) +.142 (3.61) 104 +.249 (6.32) -.475 (12.07) 41 -.166 (4.22) +.047 (1.19) 105 +.332 (8.43) +.444 (11.28) 42 -.166 (4.22) -.047 (1.19) 106 +.332 (8.43) +.332 (8.43) 43 -.166 (4.22) -.142 (3.61) 107 +.332 (8.43) +.237 (6.02) 44 -.166 (4.22) -.237 (6.02) 108 +.332 (8.43) +.142 (3.61) 45 -.166 (4.22) -.332 (8.43) 109 +.332 (8.43) +.047 (1.19) 46 -.166 (4.22) -.427 (10.85) 110 +.332 (8.43) -.047 (1.19) 47 -.166 (4.22) -.522 (13.26) 111 +.332 (8.43) -.142 (3.61) 48 -.083 (2.11) +.475 (12.07) 112 +.332 (8.43) -.237 (6.02) 49 -.083 (2.11) +.380 (9.65) 113 +.332 (8.43) -.332 (8.43) 50 -.083 (2.11) +.285 (7.24) 114 +.332 (8.43) -.427 (10.85) 51 -.083 (2.11) +.190 (4.83) 115 +.424 (10.77) +.357 (9.07) 52 -.083 (2.11) +.095 (2.41) 116 +.415 (10.54) +.190 (4.83) 53 -.083 (2.11) +.000 (0.00) 117 +.415 (10.54) +.095 (2.41) 54 -.083 (2.11) -.095 (2.41) 118 +.415 (10.54) +.000 (0.00) 55 -.083 (2.11) -.190 (4.83) 119 +.415 (10.54) -.095 (2.41) 56 -.083 (2.11) -.285 (7.24) 120 +.415 (10.54) -.190 (4.83) 57 -.083 (2.11) -.380 (9.65) 121 +.424 (10.77) -.357 (9.07) 58 -.083 (2.11) -.475 (12.07) 122 +.479 (12.17) +.279 (7.09) 59 +.000 (0.00) +.522 (13.26) 123 +.520 (13.21) +.190 (4.83) 60 +.000 (0.00) +.427 (10.85) 124 +.546 (13.87) +.095 (2.41) 61 +.000 (0.00) +.332 (8.43) 125 +.555 (14.10) +.000 (0.00) 62 +.000 (0.00) +.237 (6.02) 126 +.546 (13.87) -.095 (2.41) 63 +.000 (0.00) +.142 (3.61) 127 +.520 (13.21) -.190 (4.83) 64 +.000 (0.00) +.047 (1.19) 128 +.479 (12.17) -.279 (7.09)
I'm very thank you in advanced





RE: I need help in Regular Expressions Pattern
If I understand correctly, you want to take the first line and break it up into 6 lines as above?
www.nxjournaling.com
RE: I need help in Regular Expressions Pattern
Yes. Each line to break to 6
For all the lines of the file.
Thank you.
RE: I need help in Regular Expressions Pattern
you can use it to test the pattern you think about.
CODE -->
Imports System.Text.RegularExpressions Module NXJournal Sub Main (ByVal args() As String) Dim s As Session = Session.GetSession() Dim theUI As UI = UI.GetUI() Dim lw As ListingWindow = s.ListingWindow Dim ufs As UFSession = UFSession.GetUFSession() lw.Open() ufs.Ui.ExitListingWindow() 'Insert code here ’ Read a .vb file into a string. Dim source As String = FileText(“text path”) Dim pattern As String = "\s*[-+.\(0-9\)]+\s*" ’ Get the collection of all matches, in multiline mode. Dim mc As MatchCollection = Regex.Matches(source, pattern, _ RegexOptions.IgnoreCase Or RegexOptions.Multiline) ’ Display all variable assignments and their offset in source file. Dim m As Match For Each m In mc lw.WriteLine(" m.ToString = " & m.ToString) Next End Sub ‘ Read the contents of a text file. Function FileText(ByVal path As String) As String ’ Open a file stream and define a stream reader. Dim fs As New System.IO.FileStream(path, System.IO.FileMode.Open) Dim sr As New System.IO.StreamReader(fs) ’ Read the entire contents of this file. FileText = sr.ReadToEnd ’ Clean upcode. sr.Close() fs.Close() End Function End ModuleRE: I need help in Regular Expressions Pattern
In that case, this will probably be easier without the use of regular expressions.
Each of your values is separated by a space and there are no spaces within the individual values. In this case, you can read a line of text and use the .net "Split" method to return an array of values in the line of text. You can then reassemble the values as you desire.
CODE --> VBpseudocode
'line = a line from text file dim lineParts() as string = line.Split(" ")When this code operates on the first line of the file, the lineParts array will have 10 members:
lineParts(0) = "1"
lineParts(1) = "-.479"
lineParts(2) = "(12.17)"
etc etc
CODE --> VBpseudocode
Edit: it looks like you are reformatting the contents of an entire file. In this case, I'd suggest using a string builder object to build up the result (not individual variables as in my example code above) then write out the result of the string builder to the new file.
www.nxjournaling.com
RE: I need help in Regular Expressions Pattern
my target is the pattern that give these results and not the results themself.
If you can help in this pattern that will be nice.
Thank you for this help.
RE: I need help in Regular Expressions Pattern
www.nxjournaling.com
RE: I need help in Regular Expressions Pattern
problem I encountered and have chalange and dificulti to resolve.
RE: I need help in Regular Expressions Pattern
This pattern do the job
Dim pattern As String = "\s*[-+.]*\d+\s*[.\(\)0-9]*\s*"