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.
Questions tagged [regex]
720 questions
5
votes
2 answers
nginx: multiple matching location blocks
I try to set max-age header directive and Content-Disposition "attachment" as follows:
location / {
# set up max-age header directive for certain file types for proper caching
location ~*…

user1876484
- 155
- 1
- 1
- 5
5
votes
1 answer
url rewrite, nginx throw 404 errors, nothing in error logs
below rewrite works fine:
rewrite ^/city/restaurants$ /city/listings/restaurants permanent;
but this doesnt work
rewrite ^/city/restaurants$ /city/listings/restaurants last;
rewrite ^/city/restaurants$ /city/listings/restaurants break;
what am i…

Olaf Stavenger
- 123
- 1
- 2
- 8
5
votes
1 answer
Regex location block not working in NGINX
I have a pretty simple location block in my nginx conf that looks like this:
location ~* ^\/[a-z0-9]{24}$ {
// do some things
}
I'm attempting to catch urls that end in a Mongo ObjectId. eg: https://example.com/5550cdea6928495a25bb8df8
For some…

jwerre
- 768
- 3
- 12
- 26
5
votes
1 answer
Regex for multiple sshd Received disconnect from ... [preauth]
What fail2ban regex would catch logs like these?
Apr 9 08:48:28 server sshd[1856]: Received disconnect from 43.255.190.117: 11: [preauth]
Apr 9 09:06:05 server sshd[1936]: Received disconnect from 43.255.191.159: 11: [preauth]
Apr 9 09:06:10…

JB0x2D1
- 161
- 1
- 4
5
votes
1 answer
fail2ban-regex matches with strings, but not with log and conf files, why?
If I run
fail2ban-regex '31.22.105.115 - - [11/Apr/2014:18:09:54 +0100] "GET /admin/config.php
HTTP/1.0" 301 573 "-" "-"' '^ - - (?:\[[^]]*\]…

fpghost
- 673
- 1
- 10
- 22
5
votes
1 answer
Nginx location regex is not matching
The following has been working to cache css and js for me:
location ~ "^(.*)\.(min.)?(css|js)$" {
expires max;
}
results:
$ curl -I http://mysite.com/test.css
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 16 Jan 2014 18:55:28 GMT
Content-Type:…

Chris Montanaro
- 830
- 1
- 7
- 8
5
votes
1 answer
Regular expressions in server_name with Nginx vhost
I have something I'm trying to do with Nginx. Say I have a few users and a subdomain, and each user has a directory at /home/dev/sites/USER_ID. I would like for USER_ID.dev.example.com to point to that directory.
I've tried making a vhost files as…

SharkofMirkwood
- 152
- 1
- 1
- 5
5
votes
1 answer
postfix header_checks using regexp proper setup
I just can't seem to figure out why header_checks are not being evaluated.
I'm on Ubuntu 12.04, postfix 2.7, dovecote, spamassasin, clamav, amavis.
I add following line to /etc/postfix/main.cf :
header_checks = regexp:/etc/postfix/header_checks
And…

WJR
- 341
- 1
- 4
- 17
5
votes
2 answers
Is it possible to get the matched regex from within the apache LocationMatch directive?
I'm wondering if the following code should be working:
Order allow,deny
Allow from all
AuthType Basic
AuthName "Git"
AuthUserFile /git/.htpasswd
AuthGroupFile /git/.htgroup
Require…

tftd
- 1,498
- 7
- 25
- 40
5
votes
3 answers
Regex for sed to grab multiple lines or a better way?
I'm creating a script that connects to a server and dumps the output to a tempfile. I want to use sed in the script to grab specific information from the temp file. The output would always have the 80 char dashed line then the information I want…

krizzo
- 387
- 2
- 5
- 16
5
votes
3 answers
Bash command for regular expression substitution
What bash command can be used for regex substitution on a pipe?
cat foo.txt | someprogram

Alex
- 2,357
- 5
- 32
- 41
5
votes
1 answer
NGINX: map and try_files not working
i am using nginx to detect webp support in browser:
# Check if client is capable of handling webp
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
this code works ok and assign .webp to $webp_suffix when client support…

forke
- 143
- 10
4
votes
2 answers
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/$ { ... }
location ~ ^/(doc|img|bla|foo)/deleted/$ {…

jfix
- 211
- 1
- 2
- 3
4
votes
2 answers
Can LocationMatch Regex match Query String portion?
I am trying to use LocationMatch regex to try to match when a certain file is uploaded or downloaded through an application. The application uses query strings in the URL.
The request:
"POST
…

agent provocateur
- 246
- 4
- 14
4
votes
2 answers
fail2ban regex not matching
I must admit, regexs have always been a weak spot for me. I've never sat down and spent enough time learning them to use them effectively.
However, I really am at a loss as to why this is not matching. I'm trying to make a custom failregex to stop…

Aurelius
- 343
- 2
- 15