package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`# Parse table of SWPC event data
(?P<event>\d{4})
\s+
(?P<multi_event_flag>\+)?
\s+
(?P<time_start_flag>\w)?
(?P<time_start>\d{4})
\s+
(?P<time_peak_flag>\w)?
(?:
(?P<time_peak>\d{4})|
/{4}
)
\s+
(?P<time_end_flag>\w)?
(?P<time_end>\d{4})
\s+
(?P<observatory>\w{3})
\s+
(?P<quality>\w)
\s+
(?P<type>\w{3})
\s+
(?:
(?P<location>
(?P<lat_hg>\w\d{2})
(?P<long_hg>\w\d{2})
)|
(?P<frequency_range>
(?P<from>\w+)
\-
(?P<to>\w+)
)|
(?P<frequency>
(\d{3})
)|
(?P<no_freq>
(/{4})
)
)
\s+
(?P<particulars_1>[\w/\.\+]+)
\s+
(?:
(?P<particulars_2>
(?:\d\.\d\w[\-\+]\d{2})?
)|
(?P<particulars_3>\w{3}?)|
()
)
\s+
(?:
(?P<regnum>\d{4})|
()
)
\n`)
var str = `:Product: 20050316events.txt
:Created: 2005 Mar 17 1802 UT
:Date: 2005 03 16
# Prepared by the U.S. Dept. of Commerce, NOAA, Space Environment Center.
# Please send comments and suggestions to SEC.Webmaster@noaa.gov
#
# Missing data: ////
# Updated every 30 minutes.
# Edited Events for 2005 Mar 16
#
#Event Begin Max End Obs Q Type Loc/Frq Particulars Reg#
#-------------------------------------------------------------------------------
1590 0318 0318 0318 LEA G RBR 245 51
1620 + 0348 //// 1635 COM C RSP 30-80 CTM/1
1600 + 0408 0410 0412 LEA G RBR 245 210
1730 + 0422 1214 1511 COM G RNS 245 160
1610 0522 0528 0532 G10 5 XRA 1-8A B4.2 1.9E-04
1630 0741 0744 0748 G10 5 XRA 1-8A B1.9 7.3E-05
1630 0741 //// 0743 SVI C RSP 025-089 III/1
1640 1052 //// 1053 SVI U RSP 025-046 III/1
1650 1125 1125 1125 SVI G RBR 245 85
1650 1125 1125 1125 SVI G RBR 410 46
1660 1150 //// 1150 SVI C RSP 025-041 III/1
1670 + 1205 1208 1210 G12 5 XRA 1-8A B3.5 8.1E-05 0742
1670 1206 1206 1209 SAG G RBR 245 100 0742
1670 1207 1207 1207 SAG G RBR 410 56 0742
1670 1209 1210 1210 G12 5 XFL S02W48 3.0E+02 6.5E+02 0742
1670 1210 //// 2228 SAG C RSP 110-180 CTM/1 0742
1680 + 1217 1221 1223 G12 5 XRA 1-8A B5.1 1.4E-04 0742
1680 + 1219 1219 1219 SVI G RBR 410 310 0742
1680 1221 1222 1223 G12 5 XFL S03W50 7.5E+02 2.3E+03 0742
1690 + 1242 1245 1247 G12 5 XRA 1-8A B3.1 7.7E-05 0742
1690 1246 1246 1247 G12 5 XFL S07W48 4.3E+02 9.1E+02 0742
1700 + 1306 //// 1306 SAG C RSP 030-053 III/1
1710 + 1318 1322 1332 G12 5 XRA 1-8A B3.0 2.3E-04 0742
1710 1322 1327 1331 G12 5 XFL S07W53 2.3E+02 4.6E+02 0742
1720 + 1339 //// 1339 SVI C RSP 025-034 III/1
1750 1450 //// 1451 SVI C RSP 025-180 III/1
1760 + 1542 1547 1554 G12 5 XRA 1-8A B3.8 2.1E-04 0742
1760 + 1544 1544 1546 SAG G RBR 245 380 0742
1760 + 1544 //// 1545 SAG C RSP 030-180 III/1 0742
1760 1546 1550 1553 G12 5 XFL S07W54 4.8E+02 1.0E+03 0742
1770 1633 //// 1634 SAG C RSP 030-050 III/1
1780 1755 //// 1756 SAG C RSP 030-053 III/1
1790 + 1851 //// 1851 PAL C RSP 025-085 III/1
1800 + 1947 1953 1959 G12 5 XRA 1-8A B5.9 3.3E-04 0742
1800 1952 1957 1957 G12 5 XFL S06W57 7.3E+02 1.8E+03 0742
1810 + 2029 2034 2036 G12 5 XRA 1-8A B5.3 1.6E-04 0742
1810 + 2030 //// 2032 CUL C RSP 20-350 III/2 0742
1810 B2033 2033 2035 G12 5 XFL S07W54 7.8E+02 2.0E+03 0742
1810 + 2035 2035 2035 PAL G RBR 245 110 0742
1810 2035 U2035 2035 PAL G RBR 410 63 0742
1820 + 2049 2053 2056 G12 5 XRA 1-8A B3.6 1.3E-04 0742
1820 2051 //// 2051 CUL C RSP 40-160 III/1 0742
1820 2053 2053 A2053 G12 5 XFL S02W55 1.8E+02 3.3E+02 0742
1830 + 2116 2116 2116 PAL G RBR 245 630
1830 + 2116 2116 2116 PAL G RBR 410 130
1830 2116 2116 2116 PAL G RBR 606 67
1830 2116 //// 2116 CUL C RSP 40-460 III/2
1840 + 2304 2314 2316 G12 5 XRA 1-8A B9.8 4.6E-04 0742
1840 2309 2313 2316 G12 5 XFL S07W56 2.0E+03 5.3E+03 0742
1840 2313 2313 2318 HOL 3 FLA S06W52 SF ERU 0742
1840 2313 //// 2315 PAL C RSP 025-180 V/1 0742
1840 + 2314 2314 2314 PAL G RBR 245 160 0742
1840 + 2314 2314 2314 PAL G RBR 410 1700 0742
1840 + 2314 //// 2315 CUL C RSP 18-500 III/3 0742
`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/