Regular expression in R - Text between strings, Digit between strings and digit and text after strings : <p>I have several question about regular expressions in R, which are related to <a href="https://stackoverflow.com/questions/57384597/regular-expression-in-r-spaces-before-and-after-the-text">one</a> my previous posts in stack overflow but is a bit more expansive.</p>

<p>I have lines in a text file that represent stats. I load these files in R and want to get the values of some of these statistics.</p>

<p>First case, statistics of this type:</p>

<pre><code>system.cpu.dcache.overall_accesses::.cpu.data     42519477                       # number of overall (read+write) accesses
system.l2.overall_accesses::.cpu.data         1335898                       # number of overall (read+write) accesses
system.l3.overall_accesses::.cpu.data         1331502                       # number of overall (read+write) accesses
</code></pre>

<p>In this case, I want to catch the cache level as string (which is between "system." and ."overall_accesses") and the value as integer that is between the whitespaces.</p>

<p>cache_level = "cpu.dcache" or "l2" or "l3"
value = "42519477" etc.</p>

<p>Second case:</p>

<pre><code>system.l3.compressor.compression_size::256 58740 # Number of blocks that compressed to fit in 256 bits"
system.l3.compressor.compression_size::256 65742 # Number of blocks that compressed to fit in 512 bits"
</code></pre>

<p>In this case, I want to catch the cache level as string, the value as integer, as well as the compression size (i.e. 256 or 512). The compression size is always gonna be a number.</p>

<p>compression_size = "256" or "512"</p>

<p>Third case:</p>

<pre><code>system.l2.compressor.encoding::Base4_1 87521 # Number of data entries that match encoding Base4_1
system.l2.compressor.encoding::Base8_1 58731 # Number of data entries that match encoding Base8_1
system.l2.compressor.encoding::Uncompressed 24125 # Number of data entries that match encoding Uncompressed
</code></pre>

<p>This case is similar to the second one, in that I want to get the same things, but the encoding is a string.</p>

<p>compression_encoding = "Base4_1" or "Base8_1" or "Uncompressed"</p>

<p>For getting the lines I have in mind something like this:</p>

<pre><code>For first: if (grepl("system.+\\.*.overall_accesses::.cpu.data", line))
For second: if (grepl("system.\\.*.compressor.compression_size::\\d+", line))
For third: if (grepl("system.\\.*.compressor.encoding::\\.*", line))
</code></pre>

<p>I'm not sure whether these will work though. Then I need to get the different data.</p>

<p>Thanks.</p>
