jbanana: Badly drawn banana (Default)
[personal profile] jbanana
I'd only ever seen train track diagrams for SQL. They're a good way of showing how the syntax works rather than describing it. Turns out you can do that with regex too.

I wrote a regex to parse garbage collection logs:
(?:[-0-9.T:+]+: )?([0-9.]+): \[((?:Full )?GC(?:--|AdaptiveSizePolicy::compute_survivor_space_size_and_thresh:)? ?(?:\((?:System|Ergonomics)\)(?:AdaptiveSizeStart:)? )?(?:[0-9.]+: )?(?:[0-9.]+: )?).*?(?:\[(?:DefNew(?: \(promotion failed\) )?|PSYoungGen): ([0-9]+)K->([0-9]+)K\(([0-9]+)K\)(?:, [0-9.]+ secs)?\])?(?:[0-9.]+:)?(?: )?(?:\[(?:Tenured|PSOldGen|ParOldGen): ([0-9]+)K->([0-9]+)K\(([0-9]+)K\)(?:, [0-9.]+ secs)?\])? ?([0-9]+)K->([0-9]+)K\(([0-9]+)K\),? (?:\[(?:Perm|PSPermGen|Metaspace) ?: ([0-9]+)K->([0-9]+)K\(([0-9]+)K\)\], )?([0-9.]+) secs\](?:.*?)?
Good luck working out what that does, unless you turn it into train tracks.

And here's a regex that matches numbers divisible by 3:
([0369]|[147][0369]*[258]|(([258]|[147][0369]*[147])([0369]|[258][0369]*[147])*([147]|[258][0369]*[258])))+
source
First, it seems that you can match numbers divisible by anything (!) in regex. And second, I'm not sure it helps that much to make a divisible-by-3 train track diagram. I'm thinking "why does that work?" and at the same time "Please don't explain".

May 2025

M T W T F S S
   1234
5678 91011
12131415161718
19202122232425
262728293031 

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 7th, 2025 01:35 pm
Powered by Dreamwidth Studios