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.

720 questions
13
votes
1 answer

Why is it unnecessary to escape "/" in Nginx regular expressions?

So I've made it a thing to finally learn about regular expressions. Normally when working with regular expressions it is necessary to escape delimiters (like "/") with a "\". But when I'm using regular expressions in Nginx it would seem that "/" is…
Harold Fischer
  • 269
  • 3
  • 8
13
votes
1 answer

How do I make sec ignore a timestamp properly

I have a rule that is set up like so; In /etc/sec/rules.d I have; type=SingleWithSuppress ptype=regexp pattern=(\S+) sshd\[\d+\]: PAM \d+ more authentication failures\; logname=.* uid=.* euid=.* tty=ssh ruser=.* rhost=(.*) user=(.*) desc=Login…
Ethabelle
  • 2,052
  • 14
  • 20
13
votes
7 answers

Renaming files in linux with a regex

I had a group of files that I'd like to consistently rename, the files are named things like "System-Log-01-01-2009-NODATA.txt" "Something-Log-01-01-2009-NODATA.txt" And I wanted them as lowercase, yyyymmdd, .log…
Osama ALASSIRY
  • 824
  • 3
  • 8
  • 22
13
votes
2 answers

Grepping for CIDR ranges

From time to time I want to grep CIDR ranges out of my Apache log files. This is easy for ranges that fall on the natural boundaries (/8, /16 and /24) but not so easy for other ranges such as /17 and /25. Examples: # 192.168.0.0/16: (easy) grep "…
Ladadadada
  • 26,337
  • 7
  • 59
  • 90
13
votes
3 answers

nginx rewrite append a parameter at the end of an url

I need to configure my reverse proxy so that the following parameter will be added at the end of the url: &locale=de-de This almost works: rewrite ^(.*)$ $1&locale=de-de break; However, the problem is that I need to append '&locale=de-de' only if it…
Sascha
  • 538
  • 2
  • 5
  • 12
11
votes
1 answer

Nginx redirect all old domain subdomains to new one

I had a very long domain, so I decided to change it to a shorter and more friendly one. But since I have a lot of subdomains (in fact, I have a subdomain wildcard), I wanted to keep the subdomain while changing only the domain part. So, I made the…
ranieri
  • 233
  • 1
  • 2
  • 9
11
votes
2 answers

nginx simple regex location

I need to set a location param in nginx if the first 5 digits of the url are numbers. site.com/12345/ or site.com/12345 But I can't for the life of me seem to get the correct regular expression. None of these work. location ^/([0-9]) { } location…
The Digital Ninja
  • 764
  • 4
  • 10
  • 25
11
votes
2 answers

How to exclude files from TAR archive using regular expressions?

I have a simple question, yet I can't find or solve the answer. I want to make a tar archive, but I want to exclude some files from it using regular expression. Example of the file to exclude is this: 68x640X480.jpg I have tried this with no…
Frodik
  • 273
  • 1
  • 3
  • 14
10
votes
1 answer

Nginx proxy_pass root and specific url only

Working on a new version of an existing web app, I need nginx to forward root (/) and multiple specific URI to be forwarded to the v2 infrastructure (with proxy_pass) while not specified URI must be forwarded to v1. location = /specific_uri1 …
cyrilv
  • 325
  • 2
  • 3
  • 12
10
votes
2 answers

How can I route some emails to a script in Postfix?

How do I route all emails directed to user-*@example.com (i.e. user-1234@example.com) to a pipe command in Postfix? The idea is to create craigslist-style anonymization by assigning dynamic email aliases to each user. I can't seem to find relevant…
Nick Colgan
  • 203
  • 1
  • 2
  • 4
10
votes
5 answers

Most simple way of extracting substring in Unix shell?

What's the most simple way to extract substring on Unix shell (with regex)? Simple means: less feature less options less study Update I realized regex itself is conflicting with simplicity, and I chose the simplest one cut as the chosen answer. I…
Eonil
  • 10,459
  • 16
  • 36
  • 54
9
votes
1 answer

Show real server name in nginx logs and params passed to fastcgi?

I have configured my nginx vhosts with a regex in server_name. nginx shows the raw regex in logs and in params passed to php-fpm (I know there's $_SERVER['HTTP_HOST'] with a real value, that's not an issue). My question is how can I get nginx to put…
Aurielle
  • 91
  • 1
  • 1
  • 2
9
votes
3 answers

rsync: How to exclude Dotfiles only in topmost directory?

When performing backups under Bash with rsync, I'm trying to exclude all dotfiles and hidden directories in the top directory, but not those in otherwise targeted directories. For example: /copyme.c /.dontcopythisfile …
user937189
9
votes
4 answers

Searching for literal "> \" using ack-grep

I am looking for lines that literally have a greater than character (a ">") followed by a space followed by a backslash character (a "\") i.e., a line with this: > \ I thought escaping would allow this, and for the greater-than it does: $…
Stephen Gornick
  • 261
  • 2
  • 5
8
votes
4 answers

nginx rewrite base url

I would like the root url http://www.example.com to redirect to http://www.example.com/something/else This is because some weird WP plugin always sets a cookie on the base url, which doesn't let me cache it. I tried this directive: location / { …
ptn777
  • 115
  • 1
  • 1
  • 4
1
2
3
47 48