Regular Expression to capture a TMatchCollection of Paragraphs (Using Delphi XE 6) - regex

I'm trying to capture a collection of paragraphs that look like those shown below.
I would like to capture each paragraph in a separate collection. I have figured out how to capture each line independently, but not the full paragraph.
I'm using PCRE engine.
Any help would be greatly appreciated. I think there are may be new lines/line breaks at the end of each line also...if that makes a difference. Some paragraphs may be 5 lines long, or as short as 2 lines.
FORECAST VALID 04/0000Z 33.8N 77.3W
MAX WIND 85 KT...GUSTS 105 KT.
64 KT... 20NE 20SE 0SW 20NW.
50 KT... 40NE 50SE 20SW 40NW.
34 KT...100NE 110SE 70SW 60NW.
FORECAST VALID 04/1200Z 36.3N 74.4W
MAX WIND 90 KT...GUSTS 110 KT.
64 KT... 30NE 30SE 0SW 20NW.
50 KT... 50NE 50SE 30SW 40NW.
34 KT...100NE 110SE 80SW 70NW.
FORECAST VALID 05/0000Z 39.4N 70.2W
MAX WIND 60 KT...GUSTS 75 KT.
50 KT... 60NE 80SE 60SW 60NW.
34 KT...100NE 130SE 110SW 90NW.

Related

Is there a way to put a section of a line at the start of every subsequent line using regular expressions?

I have a text file in which there is a line with the category and then all items of that category in lines below it. This is followed by 2 empty lines and then the title of the next category and more items in the category. I want to know how I could use regular expressions (specifically with Notepad++) in order to put the category at the start of each of the item's lines so I can save the file as a CSV or TAB file.
I started by isolating one of the categories as such:
Городищенский поссовет 1541
Арабовщина 535
Болтичи 11
Бриксичи 59
Великое Село 160
Гарановичи 34
Грибовщина 3
Душковцы 5
Зеленая 182
Кисели 97
Колдычево 145
Конюшовщина 16
Микуличи 31
Мостытычи 18
Насейки 5
Новоселки 45
Омневичи 53
Поручин 43
Пруды 24
Станкевичи 42
Ясенец 33
I then got as far as getting to be finding for
(.+)(поссовет)(\t\d{4}\r\n)(^.*$\r\n)
and replacing with
$1$2\t$4
which makes the first line
Арабовщина 535
turn into
Городищенский поссовет Арабовщина 535
which is what I want to happen to the rest of the lines but I couldn't get any farther.

How to determine the number of filled drums, and the room left in each drum

Not quite a homework problem, but it may as well be:
You have a long list of positive integer values stored in column A. These are packets in unit U.
A Drum can fit up to 500 U, but you cannot break up packets.
How many drums are required for any given list of values in column A?
This does not have to be the most efficient answer, processing in row order is absolutely fine.
I Think you should be able to solve this with a formula, but the closest I got was
=CEILING(SUM(A1:A1000)/500;1)
Of course, this breaks up packets.
Additionally, this problem requires me to be able to find the room left in each drum used, but emphasis for this question should remain on just the number required.
This cannot be done with a single simple formula. Each drum and packet needs to be counted. However contrary to my comment, for this particular problem a spreadsheet works well, and there is no need for a macro.
First, set B2 to 500 for use in other formulas. If column A is not yet filled, use the formula =RANDBETWEEN(1,B$2) to add some values.
Column C is the main formula that determines how full each drum is. Set C2 to =A2. C3 is =IF(C2+A3>B$2,A3,C2+A3). Fill C3 down to fill the remaining rows.
For column D, use =IF(C2+A3>B$2,B$2-C2,""). However the last row of column D is shorter: =B$2-C21 and change 21 to whatever the last row is.
Finally in column E we find the answer, which is simply =COUNT(D2:D21).
Packets Drum Size How Full Room left in each drum used Number of filled drums
------- --------- -------- --------------------------- ----------------------
206 500 206 294 13
309 309
68 377
84 461 39
305 305 195
387 387 113
118 118
8 126 374
479 479 21
492 492 8
120 120
291 411 89
262 262
108 370 130
440 440 60
88 88
100 188
102 290 210
478 478 22
87 87 413
For OpenOffice Calc, use semicolons ; instead of commas , in formulas.

Errors with SPSS Logical Operators and Strings In a Simple Expression

I'm having some unexpected errors in achieving the following functionality. In this example code, I have the temperature on several days of the week. For this generalized example, I'm interested in determining the days that are 72,74, or 65 degrees. As an output, a variable should be created that contains the day of the week that is within this temperature range. Also, please note that in these data there is only ever 1 day that would fall within have one of these temperatures.
Monday Tuesday Wednesday Day of Interest
72 78 80
61 78 74
Monday Tuesday Wednesday Day of Interest
72 78 80 2
61 78 74 4
I wrote the following code, with the generous help of the great folks here at StackOverflow,
IF (Monday = 65 OR 72 OR 74) Day_Of_Interest = 2.
IF (Tuesday= 65 OR 72 OR 74) Day_Of_Interest = 3.
IF (Wednesday = 65 OR '72' OR 74) Day_Of_Interest = 4.
IF (Thursday = 65 OR 72 OR 74) Day_Of_Interest = 5.
but sadly it returns an error:
IF A relational operator may have two numeric operands or two character
string operands. To compare a character string to a numeric quantity,
consider using the STRING or NUMBER function.'
I tried changing the code to be akin to '65' OR '72', but this produced another error. I would really appreciate if anyone had any thoughts on how to make this work. I know the example above isn't the best, but it's the best I could think of. If you need anymore details I'd be more than happy to oblige. Thanks so much for your help!
Edit: I should say that this code does work if I am just looking for one number, say 72.
Using IF with multiple comparisons will only work this way:
IF (Monday = 65 OR Monday = 72 OR Monday = 74) Day_Of_Interest = 2.
But in this situation ANY function will be more useful:
IF any(Monday, 65, 72, 74) Day_Of_Interest = 2.
Now if you want to do this for all weekdays, you can use a loop:
do repeat day=Sunday Monday Tuesday Wednesday Thursday Friday Saturday
/Dnum=1 2 3 4 5 6 7.
IF any(day, 65, 72, 74) Day_Of_Interest = Dnum.
end repeat.
exe.

How to mix regex and string in value.replace in OpenRefine / GoogleRefine?

I'm just trying to add "+33 " and remove the first "0" in a phone number like 04 35 73 84 93 (in France) to get +33 4 35 73 84 93 in a database of contacts where a field contains only the phone number.
I tried :
value.replace(/^'0'/,'+33 ')
There is no error, but the result is the same as the original.
I thought it would be very simple (I am a beginner with Open Refine), but it seems I am missing a bigger thing here!
Anyone can help? I searched quite a lot and this seems so simple that no one is speaking about it!

Working with files I/O for beginners [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Hi all I am working on a school beginners project using files I/O in C++,
This program consist of two parts:
1) reading and processing a student data file, and writing the results to a student report file
2) modifying part 1 to calculate some statistics and writing them to another file.
For this assignment, you will be reading one input file and writing out two other files.
Your program will be run using the referenced student data file.
Part 1 Detail
Read in the student data file. This 50 record file consists of a (8-digit numeric) student id, 8 assignment's points, midterm points, final points and lab exercise points. You must again follow the syllabus specifications for the determination of the letter grade, this time, processing 50 student grades. Extra credit points are not applicable for this assignment. You will write the input student data and the results of the processing into a student report file that looks like the output shown below. In addition to the input student data, the report should contain the "total" of the assignment grades, the total and percent of all points achieved, and the letter grade. You may assume that the input data file does not contain any errant data.
The file looks like the one below:
The file that we need to read from is hyperlinked here
The student report output file should look like this:
The Student Report Output File
Student --- Asignment Grades -- Ass Mid Fin LEx Total Pct Gr
-------- -- -- -- -- -- -- -- -- --- --- --- --- ----- --- --
56049257 16 16 20 16 12 15 12 20 115 58 123 59 355 89 B+
97201934 19 15 13 19 16 12 13 18 113 72 101 55 341 85 B
93589574 13 16 19 19 18 12 6 14 111 58 108 50 327 82 B
85404010 17 19 19 19 19 10 17 19 129 70 102 58 359 90 A-
99608681 11 15 19 19 17 10 16 19 116 42 117 57 332 83 B
84918110 11 20 18 17 12 8 12 19 109 46 122 31 308 77 C
89307179 16 16 19 18 14 17 15 19 120 56 117 52 345 86 B
09250373 15 15 18 18 11 18 17 19 120 44 106 51 321 80 B-
91909583 12 14 16 19 20 11 20 16 117 66 92 50 325 81 B-
...
Part 2 Detail
Write a summary report file that contains the average total points and average percent for all students. Also, display the number of A's, B's, C's, D's and F's for the students. Your summary output file should look something like this:
The average total points = ???
The average percent total = ??
The number of A's = ??
The number of B's = ??
The number of C's = ??
The number of D's = ??
The number of F's = ??
Additional requirements
All files must be checked for a successful open. They should also be closed when you are finished with them.
Make sure you write the student id with a leading 0, if appropriate (i.e. the 8th id).
Add headings to your output report file. They should be aligned and correctly identify the column data.
Do not use global variables, except for constants, in your solution.
For part 1 How do I duplicate the file and format it to add the headings above it and the grades at the end of each file into the new duplicated file??
Any help in this matter would be appreciated
thanks in advance.
Engineering is all about converting a large complex problem into many smaller, easy to solve, problems.
Here is how I would start.
1.) Open input file.
2.) Read one line from input file.
3.) Break the input string from one line into values.
4.) Close input file.
5.) Open output file.
6.) Write results to output file.
References:
1.)File I/O
2.)std::string
3.)File I/O C
Now you're pretty much there. Take it one step at a time.