'Regex expressions for some commands

I'm trying to find the regex expressions to treat the following commands:

  • look [filename=”file_a.dat” filesize>”1048576”],I did something like that: "^look \[filename="([[:graph:]]+)" filesize>"[0-9]+"]$" and it seems isn't working.

  • announce listen 2222 seed [file_a.dat 2097152 1024 8905e92afeb80fc7722ec89eb0bf0966 file_b.dat 3145728 1536 330a57722ec8b0bf09669a2b35f88e9e leech [ssssa delhd433jh2 sdjhgd44432dskj3], I did something like that "^announce listen (([[:digit:]]+)) seed \[(([[:graph:]]+ [[:digit:]]+ [[:digit:]]+ [[:lower:][:digit:]]+)?( [[:graph:]]+ [[:digit:]]+ [[:digit:]]+ [[:lower:][:digit:]]+)*)\]$"

I'm using the regex_t api in C with posix extended expressions



Solution 1:[1]

The first one fails because the string contains the wrong kind of double-quotes.

For the second one I'm not sure exactly what you're trying to do, in the general case. If you remove \]$ from the end of the regex it matches up to just before leech. I suppose leech would match against [[:graph:]]+, but the next part would fail because [ doesn't match [[:digit:]].

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 David Knipe