# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"YYYYMMDD HHMISS beginning date of simulation"
test_str = ("=====================FORMER PATHNAMES FILE===================\n"
"/home/sun_mod/forecast/flexwrf_foshan/workdir/2022-10-30_12:00:00/1373A/\n"
"/home/sun_mod/forecast/flexwrf_foshan/workdir/2022-10-30_12:00:00/\n"
"/home/sun_mod/forecast/flexwrf_foshan/workdir/2022-10-30_12:00:00/AVAILABLE.foshan\n"
"=============================================================\n"
"=====================FORMER COMMAND FILE=====================\n"
" -1 LDIRECT: 1 for forward simulation, -1 for backward simulation\n"
" 20221030 160000 YYYYMMDD HHMISS beginning date of simulation\n"
" 20221031 160000 YYYYMMDD HHMISS ending date of simulation\n"
" 3600 SSSSS (int) output every SSSSS seconds\n"
" 3600 SSSSS (int) time average of output (in SSSSS seconds)\n"
" 180 SSSSS (int) sampling rate of output (in SSSSS seconds)\n"
" 999999999 SSSSS (int) time constant for particle splitting (in seconds)\n"
" 180 SSSSS (int) synchronisation interval of flexpart (in seconds)\n"
" 10. CTL (real) factor by which time step must be smaller than tl\n"
" 10 IFINE (int) decrease of time step for vertical motion by factor ifine\n"
" 5 IOUT 1 concentration, 2 mixing ratio, 3 both, 4 plume traject, 5=1+4\n"
" 0 IPOUT particle dump: 0 no, 1 every output interval, 2 only at end\n"
" 0 LSUBGRID subgrid terrain effect parameterization: 1 yes, 0 no\n"
" 0 LCONVECTION convection: 3 yes, 0 no\n"
" 3600. DT_CONV (real) time interval to call convection, seconds\n"
" 0 LAGESPECTRA age spectra: 1 yes, 0 no\n"
" 0 IPIN continue simulation with dumped particle data: 1 yes, 0 no\n"
" 0 IFLUX calculate fluxes: 1 yes, 0 no\n"
" 1 IOUTPUTFOREACHREL CREATE AN OUPUT FILE FOR EACH RELEASE LOCATION: 1 YES, 0 NO\n"
" 0 MDOMAINFILL domain-filling trajectory option: 1 yes, 0 no, 2 strat. o3 tracer\n"
" 1 IND_SOURCE 1=mass unit , 2=mass mixing ratio unit\n"
" 1 IND_RECEPTOR 1=mass unit , 2=mass mixing ratio unit\n"
" 0 NESTED_OUTPUT shall nested output be used? 1 yes, 0 no\n"
" 0 LINIT_COND INITIAL COND. FOR BW RUNS: 0=NO,1=MASS UNIT,2=MASS MIXING RATIO UNIT\n"
" 1 TURB_OPTION 0=no turbulence; 1=diagnosed as in flexpart_ecmwf; 2 and 3=from tke.\n"
" 1 CBL SCHEME 0=no, 1=yes. works if TURB_OPTION=1\n"
" 1 SFC_OPTION 0=default computation of u*, hflux, pblh, 1=from wrf\n"
" -1 WIND_OPTION 0=snapshot winds, 1=mean winds,2=snapshot eta-dot,-1=w based on divergence\n"
" 0 TIME_OPTION 1=correction of time validity for time-average wind, 0=no need\n"
" 0 OUTGRID_COORD 0=wrf grid(meters), 1=regular lat/lon grid\n"
" 1 RELEASE_COORD 0=wrf grid(meters), 1=regular lat/lon grid\n"
" 2 IOUTTYPE 0=default binary, 1=ascii (for particle dump only),2=netcdf\n"
" 999 NCTIMEREC (int) Time frames per output file, only used for netcdf\n"
" 0 VERBOSE VERBOSE MODE,0=minimum, 100=maximum\n"
"=====================FORMER AGECLASESS FILE==================\n"
" 2 NAGECLASS number of age classes\n"
" 7200 SSSSSS (int) age class in SSSSS seconds\n"
" 999999 SSSSSS (int) age class in SSSSS seconds\n"
"=====================FORMER OUTGRID FILE=====================\n"
" 111.0 OUTLONLEFT geograhical longitude of lower left corner of output grid\n"
" 21.0 OUTLATLOWER geographical latitude of lower left corner of output grid\n"
" 834 NUMXGRID number of grid points in x direction (= # of cells )\n"
" 600 NUMYGRID number of grid points in y direction (= # of cells )\n"
" 0 OUTGRIDDEF outgrid defined 0=using grid distance, 1=upperright corner coordinate\n"
" 1000.0 DXOUTLON grid distance in x direction or upper right corner of output grid\n"
" 1000.0 DYOUTLON grid distance in y direction or upper right corner of output grid\n"
" 5 NUMZGRID number of vertical levels\n"
" 5.0 LEVEL height of level (upper boundary)\n"
" 10.0 LEVEL height of level (upper boundary)\n"
" 100.0 LEVEL height of level (upper boundary)\n"
" 500.0 LEVEL height of level (upper boundary)\n"
" 1000.0 LEVEL height of level (upper boundary)\n"
"=====================FORMER RECEPTOR FILE====================\n"
" 0 NUMRECEPTOR number of receptors\n"
"=====================FORMER SPECIES FILE=====================\n"
" 2 NUMTABLE number of variable properties. The following lines are fixed format\n"
"XXXX|NAME |decaytime |wetscava |wetsb|drydif|dryhenry|drya|partrho |parmean|partsig|dryvelo|weight |\n"
" AIRTRACER -999.9 -9.9E-09 -9.9 -9.9E09 -9.99 29.00\n"
" Cs-137 -999.9 1.0E-04 0.80 -9.9 2.5E03 6.0E-7 3.0E-1 -9.99 -9.99\n"
"=====================FORMER RELEEASES FILE===================\n"
" 1 NSPEC total number of species emitted\n"
" 0 EMITVAR 1 for emission variation \n"
" 1 LINK index of species in file SPECIES\n"
"1 NUMPOINT number of releases\n"
"20221030 160000 ID1, IT1 beginning date and time of release\n"
"20221031 160000 ID2, IT2 ending date and time of release\n"
" 113.144 XPOINT1 (real) longitude [deg] of lower left corner\n"
" 23.0467 YPOINT1 (real) latitude [deg] of lower left corner\n"
" 113.144 XPOINT2 (real) longitude [deg] of upper right corner\n"
" 23.0467 YPOINT2 (real) latitude [DEG] of upper right corner\n"
" 1 KINDZ (int) 1 for m above ground, 2 for m above sea level, 3 pressure\n"
" 0.0 ZPOINT1 (real) lower z-level\n"
" 10.000 ZPOINT2 (real) upper z-level\n"
" 10000 NPART (int) total number of particles to be released\n"
".1000E+04 XMASS (real) total mass emitted, species 1\n"
"realease1 NAME OF RELEASE LOCATION\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html