Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [regex]

When asking regex questions, always add the tag for the specific programming language or tool (e.g., Perl, Python, or Java; vi, emacs, or ɢɴᴜ grep; etc.) you are using.

1
vote
1answer
57 views

Exchange 2010 Mail Moderation - Limit the number of recipients

I am trying to create a Transport rule to limit some users from sending e-mails to too many recipients, such action would require mail moderation approval I had an idea of using when the message ...
0
votes
1answer
30 views

exim filter regex discard rule

We are trying to discard all emails with a matching subject, example of subject: Subject: DOMAIN.COM Alert: NAME We have NOT received your payment We are trying to match any domain, Alert, and "We ...
0
votes
1answer
20 views

Using nginx rewrite to remove date from URL

Unsure why this isn't working. URL: https://example.com/blog/2009/07/23/example redirect to: https://example.com/example rewrite "^/blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)" /$5 permanent;
0
votes
2answers
497 views

Nginx Create subdomains dynamically using URL path

I am trying to rewrite/redirect to specific subdomains if the url request path matches some pattern. I would like to do something like this if i get a request like "https://example.com/users/john/...
1
vote
0answers
30 views

Iptables match special characters / SQL injection detection

I want to create an ip6tables rule to detect some well-known SQL injection attempts to web pages. example: string "admin' or '1'='1" This string should be in HTML body or sent via URI: Sending this ...
0
votes
2answers
59 views

Nginx location match multiple extensions unless path starts with specific word

How can I write a location block that matches any path ending in the following extensions: jpg|jpeg|gif|css|png|js|ico|json|xml|txt|html Unless the path starts with "/rails" (eg: /rails/randomstring/...
0
votes
1answer
21 views

Combine 2 Nginx rewrite rules with regex

I have a bunch of URL's I am redirecting in Nginx however some have a "-de" on the end of the location which I would like to remove. I am also removing the "bereich/" part of the URL: https://www./...
1
vote
1answer
62 views

How to ignore event source log

I have an event source running regularly. The problem is that http-get-dos from fail2ban will catch the IP if the user left the tab open for a large amount of time. So , I am thinking, how can I ...
0
votes
1answer
13 views

How to handle requests containing given snippets (like phpmyadmin) to another domain using NGINX?

I'd like to redirect all the requests which include any of the words "php" and "admin" (like https://example.com/phpmyadmin) to http://www.cyberpolice.cn I wrote a rewrite line and placed it inside ...
0
votes
0answers
22 views

Fail2ban regex for postfix SASL errors

In my mail.log I see frequent errors like this: Dec 2 18:07:45 ip-172-26-5-36 postfix/smtpd[32302]: warning: ip112.ip-149-56-254.net[149.56.254.112]: SASL LOGIN authentication failed: Invalid ...
1
vote
0answers
30 views

postfix header check replace from without at sign

I want to replace the from field if it does not contain the @ sign: if /^From:/ !/^From:.*@/ REPLACE From: no-reply@example.com endif Testing the regex looks promising: postmap -q "From: foo" ...
0
votes
1answer
51 views

Exim filter TLD block is blocking more than just the TLD

Need to discard emails to and from ending in a specific TLD but having an issue, example of a filter: if first_delivery and ("$h_to:, $h_cc:" contains ".win$") or ("$h_from:" contains ".win$") then ...
0
votes
0answers
46 views

Fail2ban regex not matching due to date format?

I am trying to configure a regex to prevent brute force and DDOS attacks and I am facing some issues trying to match my regex with the log file. The fail2ban version is 0.8.13. Here is what I am ...
2
votes
0answers
62 views

Regex RewriteRule in Apache 2.4 .htaccess

I want the URL: http://api.relaunch.local/rest/v1/akb/ To rewrite to: http://api.relaunch.local/?id=1873&eID=dispatch&controller=akb Where akb is the variable part. I tried endless ...
0
votes
1answer
27 views

Nginx capture regex from server name

server { listen (my server ip):80; server_name ^(.[^\.]+)(\.)(\d+)\.vm\.example\.net$; location / { return 200 '$2'; add_header Content-Type text/plain; } } what i am ...
0
votes
0answers
94 views

Fail2Ban failregex to block bulk spam from external ips

I need to build a failregex for fail2ban, to block bulk spam from external ips. I would like to build it based on this piece of the log: Oct 4 08:53:08 mail postfix/smtpd[44304]: 401E438E25DC: ...
0
votes
1answer
36 views

Spamassassin regex - is matching almost everything

I wrote a regex rule for spamassassin, which should match some words or phrases in both Subject and Body of emails. The rule is the following: header __SUBJECT_CHUJ Subject =~ /(powi.ksz.(0,5} penis....
0
votes
1answer
86 views

What's the difference between ^~ and ~ in nginx config

I'm configuring nginx and came across "^~", which seems to have a similar functionality as "~". I read the documentation here but it's still not clear to me. So how are the following locations ...
0
votes
1answer
45 views

Plesk fail2ban regex for mailbox

Can anyone help me with a special f2b Filter to track down recurring login fails on a specific mailbox? i don't want to limit fails to global postfix jail. Therefore i need a extra filter. I also ...
0
votes
0answers
18 views

fluent and parsing of logs

I'm trying to centralize logs using fluent. That part seems to be ok, I have a central fluent and other nodes and I use forward plugin to push them. Once on the central fluent I have 2 outputs, one ...
0
votes
1answer
28 views

How to exact match exact file extension .en.html with regular expression or other way in bash script

I am trying to match file name which ends with exactly .en.html using regex like .en.html$ For it works example z_.en.html but does not work with a.len.html - it matches with .len.html Any help?
0
votes
2answers
134 views

Postfix sending outgoing emails back to me via virtual_alias_maps

I have a postfix mailserver set up to forward all emails to my domain, *@example.com, to a single virtual mailbox: me@example.com. I did that with this configuration: /etc/postfix/main.cf ...
1
vote
1answer
154 views

How do I generate a regex to restore a specific folder for “btrfs restore”?

I am trying to recover files after a crash of a btrfs filesystem using: btrfs restore --path-regex 'regex' -sv -D /dev/sdXX /mnt/destination for example, to retrieve all files in /snapshots/@_2018-...
0
votes
1answer
129 views

fail2ban regex with custom nginx log format

Based on this repository I want to use fail2ban filters to analyze my nginx logs and ban suspicious requests and IPs. On my server I'm using a custom log format for nginx. Due to the fact that I'm ...
1
vote
1answer
80 views

regex: match two /'s back from end of line [duplicate]

I have a file of file paths. The depth of the directories is of various lengths and path names. I'd like to match two directories backwards (two /'s) and delete the match, creating a new file with the ...
1
vote
1answer
265 views

apt-get install packages matching wildcards

I am running Debian 8 Jessie, trying to install PHP command line intepreter from a shell script. Here is what I do: sudo apt-get install php-cli it tells me there is no php-cli. I do find there is ...
2
votes
1answer
71 views

Apache Redirect based on directory match & Add another letter to the destination URL

So here’s what I’m trying to accomplish. I have this link, I want to 301 redirect: Origin URL: https://www.example.com/folder1/page.aspx?fh_location=%2f%2fpackages%2fnl_BE%2fpr_earlybookable%3E%7b0%...
1
vote
1answer
60 views

using sed to remove character at the end of numeric string

Here's a sample of my source file: USC00020958 -7777S 656S 721S 803S 891S 975S 972S 941S 906S 809S 695S 605S USC00021001 378S 389R 448R 522R 628R 736S ...
0
votes
1answer
29 views

Password protect all directories and sub directories, but not files

As the titles suggests, I am trying to password protect all directories and sub-directories, but not the files. This is so that I can still browse through the files, and share the download links ...
1
vote
3answers
43 views

Sed or other script, and regexp solution for cutting a filename

What I need is to get 2-3 variable from filenames. I use: FILES=$(ls -tr .../Files/) for f in $FILES; do ...... The files look like this: [letters and/or numbers and (underscore or nothing)][6 ...
0
votes
0answers
152 views

Nginx rewrite query args string

I'm trying to redirect a bunch of old URL's to a new structure but having problems rewriting query arguments. My URL's are in this format: https://www.example.com/?views_qualities_groups=water-views/...
0
votes
1answer
72 views

fail2ban filter parsing error

I'm trying to add an extra filter rule to the fail2ban exim filter. I want to catch bad bot attempts that try to send auth too soon. My exim.conf filter's failregex looks like this (with the last ...
2
votes
1answer
386 views

How to create a regular expression for an openvpn fail2ban filter

Some people are trying to get into my openvpn server. For now I'm manually banning each IPs because I don't know how to setup a fail2ban regex. The content below is basically what is found in my /var/...
0
votes
0answers
96 views

server_name regex to all subdomains and primary domain, except a few words

I have a Nginx server working only as reverse proxy and and it`s redirecting requests fine, but for every subdomain i have a specific .conf file. I have three servers that hosts a couple of apps in ...
0
votes
0answers
151 views

remove characters from URL redirect in Nginx

I'm trying to remove certain characters from old URLs upon redirecting to a new URL. The characters are: ! * _ I have an old website: old.com/forums and a new website: new.com/community I'd ...
0
votes
1answer
46 views

Reverse proxy: regex to address LAN servers

I have several web servers in the LAN, addressable as http://serv1.lan/, http://serv2.lan/, etc. To be addressed from outside the LAN, requests need to be passed through an authentication reverse ...
0
votes
0answers
37 views

Using negative logic for logcheck rules

I want to filter a log file using logcheck, but instead of setting rules for the log messages I want to ignore, I would like to define rules just for the ones that I want to receive in my inbox. Is it ...
2
votes
1answer
935 views

Regular expression to restrict URL in HAProxy

I had successfully restricted an URL in my web app to certain trusted IP, using below-mentioned config in haproxy config acl trusted-ip src -f /etc/haproxy/whitelist.lst acl protected-page url /...
0
votes
0answers
57 views

ansible replace module does not work the same for another file with the same content

I am using the ansible replace module to comment the below lines ftp and telnet in the AIX /etc/inetd.conf file: ftp stream tcp6 nowait root /usr/sbin/ftpd ftpd -l -u 077 -t 180 telnet ...
1
vote
1answer
293 views

410 redirection for specific urls with same ending pattern

I need help redirecting some thousands old urls to 410 with regex The url pattern is as follows: https://www.example.com/mc-xxyyzz0-12 where the last three characters are always a number, a dash and ...
1
vote
1answer
83 views

Which special characters work in sieve regex?

I have the Roundcube Webmail v. 1.3.1 mail client with managesieve v. 8.7 extension and want to add some regex driven actions for my mail and the only documentation I found on the regex flavour is ...
1
vote
1answer
378 views

How can I make haproxy rewrite a url while retaining a variable that is the middle of the path?

I'm trying to redirect a url that looks like http://host/api/getThingByID/12345 to http://host/api/addr/12345/getThing Unfortunately, regsub() does not support capture groups. I was going to try to ...
0
votes
1answer
527 views

nginx URL rewriting regex when URL contains a specific word but not other

Please consider the following URLs. https://products.example.com/family/child https://products.example.com/products/family/child https://products.example.com/family/children https://products.example....
0
votes
2answers
765 views

Monit: use content MATCH on “check file …” if match “xxx”

I've asked this question around a week a go at StackOverflow but no answer just yet, probably is no possible but don't know where to look for that answer, I hope someone can help over here. I'm using ...
0
votes
0answers
256 views

sshd.conf fail2ban not banning cipher / key exchange

I have frequent attempts to use ssh cipher or key exchange to compromise our system. (from /var/log/auth.log) Mar 7 18:48:00 smb sshd[15022]: fatal: Unable to negotiate with 103.99.2.190 port 64720: ...
1
vote
1answer
269 views

fail2ban regex matching on testing sites, but not fail2ban itself

Hi so I'm trying to match the following log line: E/Sun, 04 Mar 2018 21:40:32 +0100: Error logging in from RemoteIP: 1.2.3.4 And after many hours I've finally got a regex that works on debuggerex, ...
1
vote
2answers
164 views

regex sieve script not matching

I have a problem on a dovecot2 mail server with a sieve script I write. The script should automatically move mail coming from a mailing list to a folder (by list name, not list id) require ["fileinto"...
0
votes
2answers
1k views

How to use a variable in a regular expression in nginx?

I've spent some time trying to find the answer before writing this question: I have several location blocks in my nginx config file that look like this: location ~ ^/(doc|img|bla|foo)/metadata/$ { .....
0
votes
1answer
605 views

How can I get nginx-botsearch of Fail2Ban to match a string but also not match that same string if it has additional trailing characters?

System is Ubuntu 16.04. Using fail2ban from the package manager (which is currently 0.9.3-1). Have enabled nginx-botsearch in jail.local. Here is my /etc/fail2ban/filter.d/nginx-botsearch.local (note ...
0
votes
0answers
493 views

Prometheus PromQL regex form Grafana

I have to write regex used in Prometheus query from Grafana (PromQL). But I have to use it on variable to cut part of it. Variable $Interface is like Ethernet1/0/1-UPLINK. And I must use this ...