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)

2
votes
1answer
1k views

Custom logcheck pattern matches using egrep, but logcheck doesn't exclude the relevant lines

We have a custom file for logcheck ignore patterns. Today I decided to add another one but it isn't working as smoothly as I'm used to. What I normally do is craft a regular expression that will ...
2
votes
2answers
443 views

Bash script to create mass series of directories

I need to create a Bash script to go into every user's home folder, seek out a wp-content folder, create a directory uploads under it, and then chmod 0756 uploads. How do I achieve this? I imagine I ...
2
votes
2answers
3k views

Regex negative look-ahead is not working for mod_rewrite between different Apache versions

I have a mod_rewrite line that works under Apache 2.2, but not under Apache 1.3: RewriteRule ^(?!index.php)(?!skin/)(?!js/)(.+) /index.php?file=$1 [NC,L] If I lose the ...
2
votes
4answers
734 views

Globally Coloring the Terminal by Regex

I know many programs use color - (vim, ack, color-ls to name a few) but there are still many cases where you're stuck with black and white. There are scripts that will color output based on regular ...
2
votes
2answers
141 views

Lex Flex variant that will do the Perl REGEX extensions

I use flex & lex a lot for stripping stuff from e-mail attachments in scritps. I wondered if there are moden versions and variants of the lex programs that have the perl REGEX extensions. I know ...
2
votes
3answers
697 views

AWStats ignore all but one sub directory

I'm using AWStats and I want to ignore everything in a subdirectory except for a particular directory, here is the directory layout: Webroot -dir_1 -dir_2 --subdir_a --subdir_b --subdir_c ... ...
2
votes
1answer
122 views

Use of backreferences in fail2ban filters possible?

From time to time, I see collections of suspect "File not found" errors in my Apache logs, basically using the pattern File does not exist: /var/www/file, referer: http://my.server.com/file In ...
2
votes
2answers
2k views

Nagios check_http - checking tomcat application status with regex & linespan

I wan't to check with our Nagios if a webapplication is running on Tomca7. I decided to use the check_http plugin with regex. I'm parsing the status-page of tomcat and check if column "Running" is ...
2
votes
2answers
65 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: ...
2
votes
2answers
986 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 ...
2
votes
3answers
4k views

apache locationmatch negative regex

I'm trying to expose a location through Apache. Normally, I have this block in my vhost that says <Location /> AuthType Basic AuthUserFile /web/.htpasswd AuthName "Test Site" ...
2
votes
2answers
878 views

nginx 0.7.65 rewrite not working for double slashes?

Using Nginx 0.7.65, I spent a few hours trying to get what seemed to be a simple nginx rewrite to work. But the two forward slashes don't seem to work properly: Url Before: ...
2
votes
1answer
717 views

apache2 fails to start due to regex

I recently enabled mod_proxy for apache2, and after having restarted my server from a power outage, the following error arose whenever I attempted to start apache2: * Starting web server apache2 ...
2
votes
1answer
142 views

nginx error log Grok pattern

I am having trouble getting the following nginx error log message to parse in the grok debugger. I have a feeling there is a stupid trick that I should use but can't figure out what it may be. ...
2
votes
1answer
442 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 ...
2
votes
1answer
493 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 ...
2
votes
1answer
817 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 ...
2
votes
1answer
638 views

Why does my SetEnvIfNoCase directive does not match requested URI?

I'm attempting to set up Apache such that various error pages display with headers/footers appropriate to the context of the error. If the user was requesting a corporate page, I want to show the ...
2
votes
2answers
795 views

nginx rewrite config

I'm pretty new to nginx and am trying to setup some pretty simple rewrite rules, but they don't seem to be working. Just for your info, this server { .. } has its server_name domain.com *.domain.com. ...
2
votes
2answers
811 views

apache question mark RewriteRule question

So i am trying to redirect from index.php?action=search&query=search text goes here to search?query=search text goes here i tried this so far but with no luck RewriteRule ^search/? ...
2
votes
1answer
1k views

how to use a rewrite rule to test the date in a cookie?

I found out that you cannot use a RewriteCond backreference as a pattern condition in the next Rewrite Cond... UPDATE: As it turns out, mod_rewrite doesn't expand any variables in the test pattern, ...
2
votes
1answer
139 views

A regexp for finding enums in Delphi source files?

The background is that I have a complicated memory issue in Delphi. But a theory is that an enum of 5 values can be the root of the bug. So my question to you is: How do I write a regexpression to ...
2
votes
1answer
34 views

htaccess regex not processing URLs properly

I'm trying to redirect (or 'rewrite') over 3000 urls for a site where we updated the SEF of most of the content pages to remove an ID number that was not needed/desired. This should be a simple ...
2
votes
0answers
221 views

nginx subdirectory to subdomain icingaweb2

I currently have icinga2 set up with the new icingaweb2 ui. it defaults to the subfolder /icingaweb as follows: location ~ ^/icingaweb/index\.php(.*)$ { # fastcgi_pass 127.0.0.1:9000; ...
2
votes
1answer
2k views

nginx return 301 / redirect

among all 'redirect in nginx' questions I couldnt find how to redirect (using return 301 and beteer no ifs) using regexps. I have a link to my website and I'd like to remove parameter a the end: ...
2
votes
0answers
43 views

List subfolders somewhere in the path with rsync

I'm developing a program, that will recursively "walk" through Linux repositories, look for PXE-related files and create gPXE configs. I met across a problem with the structure of Ubuntu catalogs on ...
2
votes
1answer
2k views

nginx: [emerg] unknown “script_filename” variable

I'm receving this error when trying to use script_filename nginx: [emerg] unknown "script_filename" variable nginx: configuration file /etc/nginx/nginx.conf test failed However script_filename is ...
2
votes
1answer
444 views

Regexp in HAProxy's reqrep for asset management

I'm hosting assets on S3 with this kind of URL: http://cdn.site.com/image.jpg In my application I automatically serve versioned URL to force browser to download new files after the deployment: ...
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 ...
2
votes
1answer
181 views

Logcheck: wildcards which include non-latin characters

On my mail server, I have a custom logcheck rule as follows, which is intended to filter messages from deliver: ^\w{3} [ :0-9]{11} [._[:alnum:]-]+ deliver\.*\): msgid=.*: saved mail to.*$ ...
2
votes
1answer
2k views

SetEnvIf regex for setting Content-Disposition HTTP header

I am attempting to use the IHS 7.0/apache 2.2 SetEnvIf directive to set the filename of a downloaded file based on a url parameter. I think I am pretty close, however if there is a space (encoded or ...
1
vote
7answers
836 views

Bash regular expression question

I am using ps -ef | grep java | wc -l to find the number of java processes running at any given time. The above command obviously counts the "ps -ef | grep java" command also in the result. To ...
1
vote
2answers
111 views

ignore lines grep

I have a very annoying message being output from a process I'm running. I'd rather not remove the line, but simply remove it with grep The messages to ignore all contain the word "requests". I could ...
1
vote
2answers
145 views

Grabbing the directory path in a message like “You have new mail in /var/spool/mail/root”

So I often get messages such as You have new mail in /var/spool/mail/root and end up typing/copy-pasting out: tail /var/spool/mail/root, which is a bit cumbersome. Is there a simple command that ...
1
vote
5answers
3k views

Don't need the whole line, just the match from regular expression

I simply need to get the match from a regular expression: $ cat myfile.txt | SOMETHING_HERE "/(\w).+/" The output has to be only what was matched, inside the parenthesis. Don't think I can use ...
1
vote
2answers
3k views

Regex negative matching trouble

I've been frustrated trying to come up with a regex to match strings based on specific file names and am hoping there's a regex ninja (I'll omit the obligatory xkcd link for the sake of time) out ...
1
vote
4answers
2k views

ls | grep regex, ignore files with .tab,

I know some regex but I don't know how to get this to work. I want to list all files that don't have .tab. and don't have ~ at the end of the filename and aren't a .o (or .bin) I can list all the ...
1
vote
2answers
570 views

Extract repository name from GitHub url in bash

Given ANY GitHub repository url string like: git://github.com/some-user/my-repo.git or git@github.com:some-user/my-repo.git or https://github.com/some-user/my-repo.git What is the best way in ...
1
vote
2answers
165 views

weird apache rewrite regex

I'm in the process of migrating a setup from apache to nginx. In this process I've come across this rewrite rule in an .htaccess file: RewriteRule ^/?(?:(?!one|two|three|four).?)+/?$ ...
1
vote
2answers
638 views

centos - how to find a filename with all the possible extensions?

I need to perform a search for "foo" and return all the filenames/ directories with this name (e.g. foo.php, foo.txt etc ). It should run through the whole filesystem and find even hidden files . ...
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
3answers
305 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
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 ...
1
vote
4answers
4k views

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/<value>/<value>/ig will not work for this situation. How do I get the same results from ...
1
vote
2answers
194 views

apache - query string rewrite rule adds percentage symbol

I've set up a rule to rewrite a query string. Although the redirection is correctly performed, a % character is appended to the rewritten query portion of the URL, like so: ...
1
vote
1answer
284 views

How to make comments in logcheck files?

how can I add comments to logcheck ignore-rules? Things I tried so far: # seems to match single # characters instead of starting a comment empty lines matches against everything $ matches against ...
1
vote
3answers
654 views

How to use Apache Piped Logs to regex replace out unwanted data in logs in real time?

I have https_acces_log log files being generated by Apache that a certain web app is logging unwanted data into the file. I can't stop the app from logging the data, so I'd like to write a ...
1
vote
2answers
1k views

Simple URI redirection / alias in Nginx

Please, how can I make this simple operation in Nginx: I wish that every requests for uris like: http://example.com/adm or: http://example.com/adm Goes to the wordpress login page: ...
1
vote
2answers
2k views

RegEx Match URL Pattern

I'm trying to come up with a regex pattern that will match any domains in this format: example.com but not this: subdomain.example.com Currently it needs to only cover the main TLDs (com, net, ...
1
vote
2answers
285 views

mod_rewrite rule

I need a mod_rewrite rule that sends all requests to index.php unless the request is for anything in the /media/ folder. I have a similar rule for lighttpd but I don't know enough about ...