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.

learn more… | top users | synonyms (1)

6
votes
2answers
1k views

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 ...
7
votes
1answer
2k views

What are PCRE limits?

In ModSecurity there are PCRE limits exceeded errors. I know I can fix this by setting rules such as: SecPcreMatchLimit 150000 SecPcreMatchLimitRecursion 150000 But, what are these rules actually ...
2
votes
1answer
275 views

htaccess email regex

I am trying to write a patter in such a way that this link : http://www.mysite.com/link/go/emailadress@gmail.com is interpreted like this : ...
1
vote
1answer
595 views

Check if folders exist in Git repository… testing if a sub-string exists in bash with NULL as a separator

I have a common git "post-receive" script for several projects, and it needs to perform different actions if an /app/ or /public/ folder exists in the root. Using: FOLDERS=`git ls-tree -d ...
0
votes
1answer
324 views

puppet master --compile logs errors to stdout

I see a bug about this that was accepted and then closed a year ago: http://projects.puppetlabs.com/issues/3670 but I'm using puppet 2.7.14 and am getting the same issue. I'm trying to use "puppet ...
1
vote
1answer
547 views

How can I rewrite following url link in nginx?

How can I rewrite following link in nginx? http://www.example.com/filename/key.value/bar.foo to http://www.example.com/filename.php?key=value&bar=foo Notice .php also, please!
2
votes
1answer
104 views

Memory usage REGEX

Could you help me to modify the following one-liner to get more precise memory usage - right now it's just an integer I would like to include first value after coma. free -m | awk '/Mem:/ {tot = $2;} ...
0
votes
1answer
216 views

How to match a string in URI with regular expression?

In my Apache config httpd.conf, I wish to setup a rule like below SetEnvIfNoCase %{QUERY_STRING} ^.*(getBook+)$ no-gzip dont-vary I am hoping to do no-gzip when my URL looks like ...
2
votes
1answer
389 views

Sed multi-line replace over escaped strings

I'm attempting to convert a mysqldump output file to PostgreSQL compatible SQL. The issue is in dealing with escaped string values. I need to go from: VALUES('blah blah blah','second string \'with ...
0
votes
1answer
608 views

How can I store {REQU­EST­_URI} in a variable, manipulate it and then use it in a RewriteCond or RewriteRule

How can I store {REQU­EST­_URI} in a variable, manipulate it and then use it in a RewriteCond or RewriteRule? Basically, here is what I am looking to do. 1.) Get the {REQU­EST­_URI} and change ...
1
vote
2answers
1k views

NGINX Reverse Proxy : proxy_cache inside if block - Possible?

I think starting with a small snippet would be wisest: location ^~ /test/ { proxy_pass http://frontend; proxy_http_version 1.1; ...
1
vote
1answer
2k views

How do I match a wildcard host in ACL lists in HAproxy?

I have the following lines in my haproxy.conf: acl valid_domains hdr(Host) -i mysite.com images.mysite.com docs.mysite.com admin.mysite.com redirect location http://mysite.com/invalid_domain if ...
1
vote
3answers
262 views

Apache mod_rewrite, multiple variables

I'm struggling a bit with mod_rewrite and replacing multiple variables with regexes. I'm trying to rewrite the following: www.mysite.com/avatars/funny/1 into: ...
-1
votes
2answers
295 views

Regular expressions to find SQL Errors in Logs

I am running a log parser to find SQL errors in my log files. If the search string (regular expression) is evaluated to true, the line will be marked. So far I used the search expression "SQL0", which ...
1
vote
1answer
308 views

Apache RewriteCond: inject string into URI between regex match groups

EDIT This works, needed to use % in place of $ for capture groups: RewriteRule (.*) http://localhost:8081/%1/%{TIME_YEAR}1101%2 [P] Having a hard time sorting this out. Need a date string ...
5
votes
1answer
521 views

nging pcre_compile error when using quantifiers

I'm having an issue with aliasing. I want to append up to the first 4 digits of the file as part of the directory. (like '../123456.jpg'=>'../123/123456.jpg' and '../12.png'=>'../12/12.png') Here is ...
1
vote
0answers
407 views

Apache LocationMatch does not work for group

I would like to configure Apache to proxy mldonkey running at localhost. Initially I have used the following configuration (in server config): <IfModule mod_proxy.c> <LocationMatch ...
2
votes
1answer
2k views

How do I format this regex so it will work in fail2ban?

I've just installed fail2ban on my CentOS server in response to an SSH brute force attempt. The default regular expressions in fail2ban's sshd.conf file do not match any entries in audit.log, which ...
0
votes
1answer
548 views

Lighttpd $HTTP[“host”] regex matching

I've set up my config like this: $HTTP["host"] =~ "(^|\.)domain1\.com$" { fastcgi.server = ( "/domain1.py" => (( "socket" => "/tmp/fastcgi.socket", "bin-path" => ...
2
votes
2answers
190 views

Regular Expression for “AND”?

Let's say I gave you the following text: allow_httpd_anon_write --> off allow_httpd_mod_auth_ntlm_winbind --> off allow_httpd_mod_auth_pam --> off allow_httpd_sys_script_anon_write --> ...
4
votes
4answers
3k views

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 ...
1
vote
1answer
205 views

Nginx equivalent to lighttpd “evhost.path-pattern”

I'm setting up a new server for my personal stuff. On the old box I've used lighttpd for almost two years now. I've read a bit about it and most people tend to switch to nginx since it's development ...
2
votes
1answer
414 views

Regular expression not working on Powershell

Background: I need to match a multiline pattern(?) in a C# source file. The regular expression will be manipulate by Powershell. I have tested and it works on RegexBuddy (with the Dot Matches ...
6
votes
1answer
1k views

Ack search for literal strings [closed]

I am sick of having to escape things when I want to search for part of an html tag. How can I ack search for exactly what I type without having to escape stuff? e.g. ack-grep 'console.log(foo' I ...
2
votes
1answer
135 views

Recursively search and replace the contents of multiple file types

I have thousands of web files(*.php, *.htm, *.html, etc) that contain an absolute path(http://site.com/sites/etc). I need to scan a directory and all subdirectories for the various file types and ...
1
vote
1answer
276 views

RewriteRule mp3 to php

I want to rewrite all .mp3 files to a php file. And I dont want to pass on the path so http://localhost/somepath/feb.mp3 http://localhost/feb.mp3 shouldn't do any difference. I came up with: ...
0
votes
1answer
395 views

Modify swatch conf files to match multiple lines below a match

We use swatch for reading PHP logs and email them to us. Currently it emails one single line of the error, but fails to match the next few lines of stack trace. For example: for log file like this: ...
1
vote
1answer
183 views

How to redirect all subdomains do one domain in Apache config file without specifying domain name?

I want to make general rule for all my domains, so I don't have to specify each of them individually. I have these two lines in my Apache config file: RewriteCond %{HTTP_HOST} ^domain\.com ...
3
votes
1answer
2k views

Fail2Ban SASL Filter Misses Failed Logins

I am using fail2ban on my mail server. I discovered this morning that there were some 5000 failed login attempts (in the course of 1 hour) via SMTP that didn't get picked up by my sasl filter. Here ...
0
votes
2answers
344 views

How do I delete a matching line, the lines above and those below in the section?

In nagios config define service{ use generic-service host_name xxx.xxx.com service_description xxx Status check_command ...
0
votes
1answer
240 views

Mod_rewrite excluding files/directories but including .php files

The traditional mod_rewrite for routing is as follows: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L] ...
0
votes
2answers
636 views

fail2ban regex to catch dovecot log entry?

Am trying to write a fail2ban regex that catches anyone who tries the user-id "administrador". For example, this log entry: Jan 2 09:55:01 mail2 dovecot: pop3-login: Disconnected: ...
3
votes
3answers
1k views

Nagios not accepting regex in command

I have this command defined: define command{ command_name check_http_sane command_line $USER1$/check_http -H $HOSTNAME$ -r "HTTP/1.1 (200|301|302|303|304|307|401|418|426)" } When I run it manually ...
2
votes
2answers
64 views

Get Apache2.2 to hide Microsoft documents that are being edited?

I have a htdocs directory where I am serving a few Microsoft Word documents. When someone is editing a document, the name of the document changes to look like something like this: ...
0
votes
2answers
4k views

How can I count instances of a regex match in a log file using PowerShell?

I have a very large log file in which I need to count the occurrences of all the variations of a particular string; that is: There are a large number of file IDs that appear in the format AA000####. ...
0
votes
1answer
205 views

.htaccess ModRewrite when moving web root content into subdirectories?

I'm cleaning up and rearranging the files on my server (basic shared hosting situation) and am digging into .htaccess to do so. I'm moving the content I had in my web root into the subdirectory of ...
1
vote
1answer
527 views

RewriteRule: cannot compile regular expression. Version support?

I'm running an Ubuntu 10.04 LTS, Apache version 2.2.14. On httpd.conf I've a rewrite rule that look like this: RewriteRule (*UTF8)^/users/([^/])([^/]+)/(.*)$ /users/$1/$2/$1$2/$3 [L] The idea ...
2
votes
3answers
238 views

How do I find this string?

I'm trying to match these file names with the find command: 4702011-10-21CR719557-R85262-ALPHA.jar 4702011-10-21CR719557-R85262-BETA.jar I'm reasonable familiar with Java-Perl regex syntax. ...
0
votes
2answers
359 views

Nginx: wild card dns redirect URL to subdomain

I'm trying to redirect the following URL Http://example.com/category/something To redirect to Http://something.example.com/category/something Where "something" could be anything. I've already ...
2
votes
2answers
892 views

fail2ban regex that uses less CPU?

Using fail2ban, I want to ban these spammers who are sending to a spamtrap address: Oct 27 09:04:22 si68 postfix/smtpd[3240]: NOQUEUE: reject: RCPT from unknown[117.197.114.222]: 550 5.7.1 ...
0
votes
1answer
1k views

Apache htaccess RewriteRule to remove trailing slash; infinite loop?

I use the following in .htaccess (mod_rewrite) to remove the trailing slash from my URLs: RewriteRule ^([a-z0-9_-]+)/$ $1 [L,NC,R=301] Of course, since the character class doesn't match a slash, ...
3
votes
2answers
3k views

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 ...
2
votes
2answers
4k views

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 ...
2
votes
1answer
1k views

nginx regex characters that require quoting?

So I was configuring nginx today and I hit a weird problem. I was trying to match a location like this: location ~ ^/([0-9]+)/(.*) { # do proxy redirects } ...for URLs like ...
1
vote
2answers
1k views

Postfix virtual domains: how to accept all subdomains except for two?

Assuming my Postfix server serves the domain example.com, I want it to accept mail for all the subdomains of example.com except for mail.example.com and in.example.com. At first I've tried using a ...
3
votes
2answers
563 views

egrep matching group not printing?

I'm trying to create a bash script that will grep lines from a file using egrep. I've created the regex that should group the information I want, the issue is trying to get the output. I've been ...
2
votes
1answer
753 views

Weird 404 issue with nginx 's.png'

This URL is invalid: http://mysite.co.uk/assets/images/whymysite/viewoptions.png However, if I replace the 's' at the end before .png, with ANY other standard character (that I've tried so far, it ...
4
votes
3answers
5k views

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 ...
0
votes
1answer
157 views

Apache redirect to another domain all URLs, except for ones starting with substring

Can anyone help me achieve a redirect in Apache from http://subdomain.example.com/ to http://example.com/ for all URLs, EXCEPT the ones starting with "files/"? Thank you
3
votes
3answers
6k views

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 ...