1
$\begingroup$

click here for image

My intention is to select only those packages whose name do not contain adlib or ads. But if i add *adlib* and *ads* it selects all packages containing the substring adlib and ads. So i need a regular expression to select all packages that do not contain substring adlib and ads.

$\endgroup$
4
  • 2
    $\begingroup$ This seems to be a question about the syntax of whatever regular expression system you're using, and not really a question about computer science. (Especially given your comment on Shreesh's answer, which seems to be a request for the same thing but with different syntax.) $\endgroup$ Commented Feb 14, 2016 at 9:13
  • $\begingroup$ I think Jose does not know much about regular expressions, but question is valid in the sense 'how one can compute complement of regular language in the specific case'? $\endgroup$ Commented Feb 14, 2016 at 14:02
  • $\begingroup$ @Shreesh, again, that depends a lot on the regular expression format in use (and some tools, e.g. grep(1)) have an option to select lines that don't match). $\endgroup$
    – vonbrand
    Commented Feb 14, 2016 at 17:11
  • $\begingroup$ I'm voting to close this question as off-topic because this is a question of a specific regular expression format $\endgroup$
    – vonbrand
    Commented Feb 14, 2016 at 17:12

1 Answer 1

2
$\begingroup$

Let $[$^$x]$, $[$^$xy]$ be short cuts for $\Sigma - \{x\}$, $\Sigma - \{x, y\}$ etc., i.e., $[$^$a]$ will be regular expression: $(b+c+d+\dots)$.

Then the regular expresseion for words not containing ads or adlib would be

$[$^$a]^*(a[$^$d][$^$a]^*+ad([$^$sl][$^$a]^* $ $+ adl[$^$i][$^$a]^* + adli[$^$b][$^$a]^*)^* (\epsilon + a +ad + adl + adli)$.

Basically we wait for an $a$ and then check it is not followed by the disallowed combinations.

Since regular expressions have built in operators for union, kleene and concatenation only, we will always have trouble with intersection, complement and minus operations. Basically the operation you want in your question is the complement.

$\endgroup$
2
  • $\begingroup$ sir, is there a way to write above expression without using ^,[],+ .. $\endgroup$
    – Jose Kj
    Commented Feb 14, 2016 at 8:02
  • $\begingroup$ As I mentioned [^a] = (b+c+d+...+A+B+...+'.'+'/'+...). If you substitute it in the expression above, it will be very long, hence the shortcut. $\endgroup$ Commented Feb 14, 2016 at 8:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.