Community discussions

MikroTik App
 
andreacoppini
Trainer
Trainer
Topic Author
Posts: 498
Joined: Wed Apr 13, 2005 11:51 pm
Location: Malta, Europe

RegEx help

Sun Mar 30, 2014 1:03 pm

Hi all, this one should be easy for you scripters out there.

I want to create some Web Proxy rules where I want to match "example.com" and "*.example.com" (eg. www.example.com, whatever.example.com, www1.www2.example.com, etc) but not www.thisisanexample.com.

I tried this:
^(.*\.)?example.com$
.. which gave me the desired result when tested here http://regexpal.com/

but it didn't work in RouterOS.

Any ideas?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Sun Mar 30, 2014 1:22 pm

[revised 2021-09-24 for 6.47.10]

It's more simple than you think:

some example:
block any *.doubleclick.net (Advertising provider)
/ip proxy access
add action=deny dst-host=":(^|\\.)doubleclick\\.net" redirect-to="192.168.1.1/mikrotik_logo.png"
Why redirect-to="192.168.1.1/mikrotik_logo.png"?
If you broken the contents of some sites with blocking, the webpage are corrupt, in this way a MikroTik logo are displayed instead of page error.... :o
You can use any type of image, but must be one image for working well...

block any domain where facebook is one part of name
/ip proxy access
add action=deny dst-host=":*\\.facebook\\.*" redirect-to="this.is.my.site.com/you_are_fired.http"
(for blocking some sites also on https another way is needed....)

block third level domain *.ads.thisexample.org but not the main domain
/ip proxy access
add action=deny dst-host=":(^|\\.)ads\\.thisexample\\.org" redirect-to="192.168.1.1/mikrotik_logo.png"
Last edited by rextended on Fri Sep 24, 2021 3:31 pm, edited 23 times in total.
 
andreacoppini
Trainer
Trainer
Topic Author
Posts: 498
Joined: Wed Apr 13, 2005 11:51 pm
Location: Malta, Europe

Re: RegEx help

Sun Mar 30, 2014 1:35 pm

Ciao Rex,

thanks for the comprehensive reply, but what I'm looking for is to block:

*.doubleclick.net
doubleclick.net

The rules you specified will only block http://*.doubleclick.net, but will allow http://doubleclick.net.

I could use *doubleclick.net, but that will also block http://www.thisisnotdoubleclick.net, which I do not want.

I want to:
Block http://*.doubleclick.net
Block http://doubleclick.net
Allow http://*.thisisnotdoubleclick.net
Allow http://thisisnotdoubleclick.net
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Sun Mar 30, 2014 1:48 pm

Use first example: post fixed

Buon Lavoro!
Last edited by rextended on Fri Sep 24, 2021 3:32 pm, edited 3 times in total.
 
andreacoppini
Trainer
Trainer
Topic Author
Posts: 498
Joined: Wed Apr 13, 2005 11:51 pm
Location: Malta, Europe

Re: RegEx help

Sun Mar 30, 2014 1:55 pm

Grande!!

That's exactly what I was looking for... looks like I had a typo and added an extra : in ROS... :shock:

Buona domenica e grazie!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Sun Mar 30, 2014 2:18 pm

Grazie, anche a te!

Ciao.
Last edited by rextended on Fri Sep 24, 2021 3:33 pm, edited 1 time in total.
 
freemannnn
Forum Veteran
Forum Veteran
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

Re: RegEx help

Sun Mar 30, 2014 4:25 pm

Use the last example:

And, on end, but are many possibilities, for block any doubleclick.net or *.doubleclick.net
/ip proxy access
add action=deny dst-host=:^(.*\.)?doubleclick.net$ redirect-to=192.168.1.1/mikrotik_logo.png
The : start one regular expression :lol:


Buon Lavoro!
can you please write the correct line. i get error in terminal when i write this.
expected end of command (line 1 column 28)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Mon Mar 31, 2014 2:02 pm

I fixed my first post.
Last edited by rextended on Fri Sep 24, 2021 3:43 pm, edited 2 times in total.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: RegEx help

Tue Apr 01, 2014 12:04 am

Is the karma collection some kind of contest?

Sent from Android by Tapatalk.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 12:16 am

No, we are not payed for giving support, is only a little satisfaction... nothing else. :)
Like a little cherry for each problem solved. 8)

On reality, give support to other users, is giving me some new ideas...
Gain on both parts!
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: RegEx help

Tue Apr 01, 2014 12:19 am

I know that. Just was provocated by repeating readings of karma requests...

Sent from Android by Tapatalk.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 12:25 am

One example: this request not are on my signature, :o
If you see all my posts, i make the "suggestion" when I put some code or very useful informations. :lol:

On some user the request are permanently written on the signature... :lol:
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RegEx help

Tue Apr 01, 2014 12:36 am

On some user the request are permanently written on the signature... :lol:
Just FYI... I for one, and I'd guess jarda and others too... find "in post" prompts more annoying than signature prompts.

Why? Because "in post" prompt requires an extra effort from you, since you actually had to write it, as opposed to it being automatically added. This in turn makes it seem like you're "begging" for it, like it's really important to you, as if it's a contest or something, and it's the "begging" that's annoying. Karma should be a "BTW thing", not "in-your-face thing".
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 12:47 am

On some user the request are permanently written on the signature... :lol:
Just FYI... I for one, and I'd guess jarda and others too... find "in post" prompts more annoying than signature prompts.

Why? Because "in post" prompt requires an extra effort from you, since you actually had to write it, as opposed to it being automatically added. This in turn makes it seem like you're "begging" for it, like it's really important to you, as if it's a contest or something, and it's the "begging" that's annoying. Karma should be a "BTW thing", not "in-your-face thing".
Just FYI :?
"BTW what?" :?
Slang to English?

I write on the signature only the essential ...

I find more annoying: the acronyms or slang abbreviations not understandable!
This forum is read all over the world,
one thing is to use the English language,
one thing is for "slang" abbreviations. Are not understandable to non-english users.
Obviously some acronyms as a raid dhcp "etc." MUST be used ...
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RegEx help

Tue Apr 01, 2014 1:24 am

Just FYI :?
"BTW what?" :?
Slang to English?
Not English slang - internet slang. See UrbanDictionary.com: BTW, FYI.

While we're at it, here are a few other common ones - LOL, AFAIK, AFAIR, YMMV, IRL, IDK.

Internet slangs are sometimes used even in non-English forums and chats, due to them being "common knowledge" among the people present in said forums/chats. "LOL" and "BTW" are particularly popular. In fact, you'll notice the text of the " :lol: " emoticon is "lol".
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 1:30 am

Both we have express own opinion,
thanks to be polite.
Last edited by rextended on Fri Sep 24, 2021 3:34 pm, edited 1 time in total.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: RegEx help

Tue Apr 01, 2014 1:34 am

What a battle here! Even the abbreviations are usually well known, it is better to avoid them and write as nice as possible.

Sent from Android by Tapatalk.
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: RegEx help

Tue Apr 01, 2014 1:45 am

What a battle here! Even the abbreviations are usually well known, it is better to avoid them and write as nice as possible.
Battle?!? Wait. Who? Me? Noo...

When you say "nice", do you mean as in "polite" or as in "elegant"? Because I think I'm being polite... though maybe I'm not always elegant. Certainly not in this instance. Though in my defense, it's a non-elegant issue that brought my attention, making it easy to loose any elegance in writing about it.
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: RegEx help

Tue Apr 01, 2014 8:49 am

Battle was kind of hyperbole. I was surprised what discussion could start one BTW. Yes, I mean both even I agree with you. Anyway it seems we have lost the topic which is also my fault. Sorry for that. Have a nice day!

Sent from Android by Tapatalk.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26288
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: RegEx help

Tue Apr 01, 2014 12:23 pm

"Sent from Android by Tapatalk" is also an in-post thing :)
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 1:07 pm

"Sent from Android by Tapatalk" is also an in-post thing :)
+10!
 
jarda
Forum Guru
Forum Guru
Posts: 7756
Joined: Mon Oct 22, 2012 4:46 pm

Re: RegEx help

Tue Apr 01, 2014 2:15 pm

Fine. Removed.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Tue Apr 01, 2014 2:15 pm

Fine. Removed.
Thanks!

Sent from my ET2220IUTI using Internet Explorer
 
freemannnn
Forum Veteran
Forum Veteran
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

RegEx help

Thu Apr 03, 2014 12:01 am

Use the last example:

And, on end, but are many possibilities, for block any doubleclick.net or *.doubleclick.net
/ip proxy access
add action=deny dst-host=":^(.*\\.)?doubleclick.net\$" redirect-to="192.168.1.1/mikrotik_logo.png"
The : start one regular expression :lol:


Buon Lavoro!
can you please write the correct line. i get error in terminal when i write this.
expected end of command (line 1 column 28)
And, on end, but are many possibilities, for block any doubleclick.net or *.doubleclick.net
/ip proxy access
add action=deny dst-host=":^(.*\\.)?doubleclick.net\$" redirect-to="192.168.1.1/mikrotik_logo.png"
The : start one regular expression :lol:

IF YOU PASTE THE LAST LINE ON TERMINAL:
YOU MUST USE
add action=deny dst-host=":^(.*\\.)\?doubleclick.net\$" redirect-to="192.168.1.1/mikrotik_logo.png"
instead!
The ? character are not directly peaste-able on terminal.
If you use winbox for edit acces rule, you must put only ":^(.*\.)?doubleclick.net$" on the fileds (without quotes)
I have removed the wrong code. Read all on my first post. I fix only my first post, not the various quote. :lol:

If anyone use my code, or find interesting my ideas, please add Karma!
Thanks.
still dont get it.
What is the correct line i should paste in terminal ?
Can you write it here in a new post?
I dont understand the thing you say about ? And quotes etc.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Thu Apr 03, 2014 12:11 am

Where are you from?
What is your language?
I dont understand the thing you say about ? And quotes etc.
My nickname on the forum is "rextended" without the quotes...

What is the correct line i should paste in terminal ?
What version of RouterOS you use?
This script is tested for RouterOS 5.25+ and 6.7+
If you use previous version, i do not know your results.

If you simply copy previous script and paste directly on winbox, you can get an error, because when you paste directly from web page obtain on some browser
/ip proxy accessadd action=deny dst-host=":^(.*\\.)\?doubleclick.net\$" redirect-to="192.168.1.1/mikrotik_logo.png"
without space.

The script must be pasted first inside a text editor like word or wordpad (not notepad) and re-copied for pasting on terminal.

If you are not familiar, use this line for copy & paste on new terminal inside winbox:
/ip proxy access add action=deny dst-host=":(^|\\.)doubleclick.net\$" redirect-to="192.168.1.1/mikrotik_logo.png"

If you got error, you have done some wrong, sorry.
Last edited by rextended on Fri Sep 24, 2021 3:40 pm, edited 4 times in total.
 
freemannnn
Forum Veteran
Forum Veteran
Posts: 700
Joined: Sun Oct 13, 2013 7:29 pm

Re: RegEx help

Sun Apr 06, 2014 10:15 pm

thanks for the last reply. it worked.
i am testing web proxy blocking sites.
i want to block for example porn sites.
i added *porn* and it works! but...
when a url for example "en.wikipedia.org/wiki/Pornography" with P letter capital, it does not work. you can still open the web page.
so how you tell reg exp to ignore case sensitive?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: RegEx help

Fri Sep 24, 2021 3:10 pm

so how you tell reg exp to ignore case sensitive?
RegEx used on RouterOS do not have that flag (ignore case)

Who is online

Users browsing this forum: Qalderu and 24 guests