PMATCH(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… pmatch(9) β€” kernel dev manual realness

okay so bestie, welcome to PMATCH(9) from the Kernel Developer's Manual β€” yes we're in kernel land, bring your flashcards πŸŽ€


✨ NAME ✨

pmatch β€” it does pattern matching on strings, that's the whole vibe πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <sys/systm.h>

int
pmatch(const char *string, const char *pattern, const char **estr);

🌸 DESCRIPTION 🌸

So what it does is extract a substring matching pattern from string β€” like it goes digging in there and pulls out the match for you 🫢

And if estr isn't NULL, it points at the end of the longest exact or substring match. iconic, honestly.

pmatch() uses these metacharacters, and bestie you will be memorizing them:

  • ? β€” matches any single character. one (1) character, no more, no cap πŸ’…
  • * β€” matches any character 0 or more times. zero, one, a hundred, it does not care ✨
  • [ β€” defines a range of characters that will match. the range is defined by 2 characters separated by a -. and β€” important β€” the range definition has to end with a ]. also, a ^ following the [ will negate the range. lowkey chef's kiss 🌈

πŸ‘‘ RETURN VALUES πŸ‘‘

pmatch() will return:

  • 2 β€” exact match, we ate πŸ”₯
  • 1 β€” substring match, still slay
  • 0 β€” no match 😭
  • -1 β€” if an error occurs πŸ’€
fr fr remember these are literal numbers, not booleans β€” 2 is not 1, do not come for me πŸ™ˆ

mwah πŸ’œ that's the whole page. this one came from Debian, dated October 12, 2003 β€” vintage, but still serving. go forth and match some patterns, bestie πŸ§šβ€β™€οΈβ­

πŸ“¦ where this page comes from