Skip to content

Instantly share code, notes, and snippets.

@pronebird
Last active October 1, 2021 12:53
Show Gist options
  • Save pronebird/ff87886e6aa80e684a422f480117a4b4 to your computer and use it in GitHub Desktop.
Save pronebird/ff87886e6aa80e684a422f480117a4b4 to your computer and use it in GitHub Desktop.
Regex for parsing sprintf style format with Apple privacy extensions
# Ignore escape sequences %%
(?<!%)
# Match %
%
# Match extended attributes supported by OSLog, ie: {public, uuid_t}
# See https://developer.apple.com/documentation/os/logging for built-in value decoders
(?:\{([\w-,\s]+)\}){0,1}
(
# Match length modifiers
# See https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265
(?:(hh|ll|h|l|q|L|z|t|j){0,1}
# Match format specifier (see the link above)
[@dDuUxXoOfeEgGcCsSpaAF])
# OR
|
# Match OSLog built-in type decoders
(?:\.\*\d*P)
)
time_t
%{time_t, public}d
2016-01-12 19:41:37
timeval
%{timeval, private}.*P
2016-01-12 19:41:37.774236
timespec
%{timespec}.*P
2016-01-12 19:41:37.2382382823
errno
%{errno}d
Broken pipe
iec-bytes
%{iec-bytes}d
2.64 MiB
bitrate
%{bitrate}d
123 kbps
iec-bitrate
%{iec-bitrate}d
118 Kibps
uuid_t
%{uuid_t}.*16P
%{uuid_t}.*P
10742E39-0657-41F8-AB99-878C5EC2DCAA
Sprintf standard
%s %d %O %LF %%f %s
Hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment