udev 规则 attrs 正则表达式接受

udev rules attrs regular expression acceptation

我正在尝试包含一个 udev 规则,以根据 usb 设备属性创建自定义的 /dev/ 条目。我有两个不同的条形码扫描器,它们在制造商属性中包含条形码扫描器和条形码扫描器。

所以我想知道是否可以通过将正则表达式添加到 ATTRS{manufacturer} 来使其工作,如下所示:

ATTRS{manufacturer}=="(([bB]ar\ ?[Cc]ode\ ?)([Ss]can\ ?(ner)?))"

或者我应该:

ATTRS{manufacturer}=="\([Bb]ar\(\s\?\)[Cc]ode\s\?[Ss]can\)"

上面显示的正则表达式将接受以下变体:

Bar code Scanner
barcode scanner
barcodescanner
Barcode Scanner
bar code scanner
bar code scan
Bar Code Scan
BarCode Scaner
barCode scanner

来自udev man page

It supports the following pattern characters:

  • "*" Matches zero, one, or more characters.
  • "?" Matches any single character, but does not match zero characters.
  • "[ ]" Matches any single character specified within the brackets. For example, the pattern string "tty[SR]" would match either "ttyS" or "ttyR". Ranges are also supported within this match with the '-' character. For example, to match on the range of all digits, the pattern [0-9] would be used. If the first character following the '[' is a '!', any character not enclosed is matched.
  • "|" Separates alternative patterns. For example, the pattern string "abc|x*" would match either "abc" or "x*".

在你的情况下 "[Bb]ar[Cc]ode [Ss]can*|[Bb]ar [Cc]ode [Ss]can*" 应该有效。