Regex in rules does not seem to support negative lookahead - can't match "anything except for foobar"
- PipeWire version (
pipewire --version
): pipewire Compiled with libpipewire 0.3.77 Linked with libpipewire 0.3.77 - Distribution and distribution version (
PRETTY_NAME
from/etc/os-release
): PRETTY_NAME="openSUSE Tumbleweed" - Desktop Environment: KDE Plasma
- Kernel version (
uname -r
): 6.4.11-1-default
Description of Problem:
My intention is to route certain applications to certain virtual sinks (so that I can separate them in OBS recordings by using those virtual devices as OBS sources) I wanted to create a rule that matched "everything but obs", and eventually "match everything except for any of these apps", which I'd generally do by using a negative lookahead, but no matter how I tried, I couldn't get it to work. For example, something like:
application.process.binary = "~^(?!obs$|neverroutethis$).*"
Should match everything except 'obs' or 'neverroutethis'. In effect, it will still match obs.
Simpler regex has a similar effect, to give one example:
application.process.binary = "~(?!obs$)"
Naturally, I hit the search engines for methods to regex match 'everything except foo', and I tried them all, in case it's just that my regex sucked, but nothing worked. The same regex which worked well in other apps such as grep or sed did not work in pipewire rules.
I'm working around this with a rule that matches obs and takes no action, and then another rule afterwards which matches everything and takes the actions intended:
context.rules = [
{
matches = [
{
# all keys must match the value. ~ starts regex.
application.process.binary = "obs"
}
]
actions = {
}
}
{
matches = [
{
# all keys must match the value. ~ starts regex.
application.name = "~.*"
}
]
actions = {
update-props = {
target.object = "Default Media Bus In"
}
}
}
]
This works, but could get a little messy as my list of "don't match this app" grows, and it would be nice to have a single rule doing the job of these two.
How Reproducible:
100%
Steps to Reproduce:
- Attempt to create a rule that matches everything except for certain strings by using regex negative lookahead or any other means of regex negation
- Note that the rule does not function as intended, the negated portion is not excluded from the match.
Actual Results:
Matches string which are excluded by means of negative looahead/lookbehind/other negation methods
Expected Results:
Negation of match string functions as expected and action is not taken
Additional Info (as attachments):
I'm very much satisfied with a "you're doing it wrong" response which might suggest another means to achieve a match such as
application.name = "anything except foo, or bar, or baz"