RegEx help to match a word but exclude if it occurs in an URL


Hello everyone,

first of all: thank you for your amazing bot!

At the moment I got a little problem with the keyword feature using RegEx. I want to setup a few keywords to trigger a response, but only if the keyword does not occur in an URL.

Keyword: youtube

Response should be triggered if a user writes:
Do you have a youtube channel?
Are you on YouTube?
Is there a YOUTUBE channel?

and so on. It should trigger with any possible way a user could write youtube, except if it’s inside of an URL, like in song requests or links that are postet.

I did not figure it out myself yet, so I thought your support might be useful and also others will benefit from it.

Thank you and kind regards




I already tried that. Unfortunately it will still get triggered when I post a youtube link


Is link filter enabled? If yes, add & to whitelist.


Link filter is disabled.


here is one example I tried, but it somehow does not work (even though it does on



Try this:


Thanks, it works like that but I would like to have everything in a single expression. Like that I would need to make multiple keywords with expressions for YOUTUBE,, YouTube etc.

Any chance you can help me with that?


YOUTUBE, YouTube and even yOuTuBe are already catching by this regex.
If you don’t use link filter then there is no need to take into account, I think.


Well, that is exactly the problem: they are not.

I expect the bot to reply on the keywords YOUTUBE, YouTube and even yOuTuBe - but right now the bot only replied when I enter youtube or a sentence like “can I find you on youtube?”


I just tried and everything works for me. What version of PhantomBot do you have?


PhantomBot Version: 2.4.2 (Revision: 5c75a7b2)
Operating System: Linux
Java Version: 1.8.0_131-8u131-b11-1~bpo8+1-b11

I should also mention that I am using the beta-panel:
Panel Version: 1.2 (BETA)
Panel Template: AdminLTE


Me too using beta-panel. I have no idea why caps are not caught by regex in your chat. The only thing I can advise is to reboot the bot.


I just did. Didn’t help :frowning:


Here’s how it happens in my console:

userName: youtube
[CHAT] .timeout userName 5 Blacklisted word
userName: YouTube
[CHAT] .timeout userName 5 Blacklisted word

Therefore, the question goes to another problem: why your bot’s regex is a case sensitive.


So you are using the blacklist feature?
Just to be clear: I am using the keywords feature, I don’t see a need for the blacklisting in this case


Oh, I’m sorry for my inattention :smiley:

For some reason, the bot does not perceive /.../i which allows you to ignore case.

I know this is the stupidest regex ever but it should work:

NOTE: Don’t add this through the beta-panel, it turns uppercase letters into lowercase, add it through the old panel.


No problem, Sir!
I am the grateful one getting help by you.

This finally worked - but did we just discover a bug in the RegEx for the keywords feature? @devs? :smiley:


We implement a case-sensitive regular expression check. The RegExp() constructor doesn’t accept flags within the pattern. There is an optional parameter for flags on the constructor that we do not expose.


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.