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
3
votes
1 answer
Making Nginx and PHP-FPM code version agnostic
This is not a question about a current problem but more of a "preventive medicine" question:
I have the following code which is part of a much larger scrip I use to rise up Nginx environments on Debian-oriented systems:
sed -i 's/post_max_size \=…

Arcticooling
- 1
- 3
- 7
- 22
3
votes
2 answers
Redirect of all the URLs that contain 1 word in specific, but that do not contain other words
I am migrating my website to another platform, but while I finish developing all the pages of the new website, I need my users to navigate between the 2 platforms.
So I need to make a 301 redirect of all the URLs that contain 1 word in specific, but…

Alorse
- 221
- 1
- 2
- 6
3
votes
1 answer
Check Varnish ACL via X-Forwarded-For when behind one or more(!) reverse proxies
I have Varnish running behind a reverse proxy (running on localhost, for SSL offloading). The proxy sets the X-Forwarded-For header or adds itself to it if the header already exists.
When I do ACL checks of course I want to check against the…

Martijn Heemels
- 7,728
- 7
- 40
- 64
3
votes
1 answer
Escaping special characters in grep regex
I am trying to run a grep regular expression on a file, where I have to exclude lines where "00" and "0" appear. I came up with this expression:
grep -a -E \"stored\"\:\ \"\*123\*(?!00)[0-9]{2,5}\#\" $filename
But when I try to run it in bash, I…

Unpossible
- 249
- 1
- 7
- 20
3
votes
1 answer
How to simplify Nginx Mapping regex rules?
I don't know if this question is allowed or not. If not, forgive me :)
Anyway, I have a mapping rule for nginx redirection
/hotel/xyz/abc /hotel/xyz/abc-nana;
/hotel/xyz/abc/ /hotel/xyz/abc-nana;
~^/hotel/xyz/abc\?(.*) /hotel/xyz/abc-nana?$1;
My…

Oscar Yuandinata
- 131
- 4
3
votes
1 answer
Insert a variable route path into nginx location configuration
I have a simple user based storage for images where I have a main folder say 'users' and within it, my server creates variable folders to store images for each user. The string used for the folder is randomly generated. What I would like is to…

AlanZ2223
- 173
- 1
- 2
- 6
3
votes
2 answers
ubuntu 14.04 Apache 2.4.7 mpm_event Files and FilesMatch not working
We recently switched our Apache 2.4.7 mode from mpm_pre-fork to mpm_event.
Since then we haven't been able to get our Files directive to work.
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
I…

Aaron
- 131
- 5
3
votes
1 answer
Apache HTTP LocationMatch Redirect using Negative RegEx
I'm trying to create a Redirect using Apache HTTP Server's mod_alias and core on my system:
# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.1 (Maipo)
# rpm -q httpd
httpd-2.4.6-31.el7_1.1.x86_64
#
requirement is to redirect…

alexus
- 13,112
- 32
- 117
- 174
3
votes
1 answer
Fail2ban: regex test succeed but fail2ban does not ban any IP
I can't ban any ip, thought when I test my regex, it has +2000matches:
> fail2ban-regex '/var/log/nginx/access.log' '/etc/fail2ban/filter.d/bad-request.conf'
Date template hits:
|- [# of hits] date format
| [1172344]…

Olaf Stavenger
- 123
- 1
- 2
- 8
3
votes
1 answer
fail2ban regex filter doesnt work with nginx log files
I have been banging my head all day trying to match my regex filter to my access.log with no luck. I have installed fail2ban on a gentoo server and its running fine (i manually baned my own IP and it works) but fail2ban regex fails and return 0…
user314215
3
votes
2 answers
How to check if LocationMatch regex is working?
I have location match regex
ScriptAlias /script /var/www/somescript.bash
Action some-handler /script virtual
SetHandler some-handler
Now when test that regex…

pregmatch
- 303
- 1
- 5
- 14
3
votes
2 answers
Replace Wildcard Character in Filenames
I can't get this to work:
I have hundreds of files that our database developer has foolishly put asterisks in, so that we have files named like this:
*1*_Floorplan.jpg
I need to recursively (two levels in) search and replace all instances of "*" in…

neezer
- 810
- 3
- 12
- 29
3
votes
3 answers
Nginx add trailing slash without rewrite
I am trying to create redirect to add trailing slash,
location / {
if($request_uri ~ ^([^.]*[^/])$){
return 301 https://$host$request_uri/;
}
}
I have no idea how to do matching in if, when I simply create redirect with / - it works, just…

sdooo
- 171
- 1
- 1
- 8
3
votes
0 answers
php-fpm: Maintain php_mod logging format
I recently switched all my lab servers from apache pre_fork/mod_php to apache worker/fcgi/php-fpm, and after getting everything set-up correctly, I noticed one last issue; php-fpm is adding it's own logging "header" to the php error log.
So this…

Mike Purcell
- 1,708
- 7
- 32
- 54
3
votes
4 answers
Perl in place edit within a script
I need to edit a file in place within a perl script, so the oft used one liner:
perl -p -e s///ig
will not work for this situation. How do I get the same results from within a perl script?
open(CRONTAB, "+

Shawn Anderson
- 542
- 7
- 14