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

18
votes
1answer
446 views

Why bracket a single letter in a grep regex?

I've seen several instances where people are doing this: grep [f]oobar But I don't understand why that is preferable to grep foobar
8
votes
1answer
164 views

Is there a tool that can top-ify an input stream?

I come across quite a few use cases where it would be very useful to take input from a (usually newline-delimited) stream and summarise it in a top-like fashion (see top, iotop, etc). A kind of ...
7
votes
4answers
1k views

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

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 ...
6
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 ...
5
votes
3answers
2k views

Bash command for regular expression substitution

What bash command can be used for regex substitution on a pipe? cat foo.txt | someprogram
5
votes
1answer
401 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 ...
4
votes
4answers
4k views

Copy multiple folders to a single destination with robocopy

I'm looking for a solution to use robocopy to copy several folders from a directory onto a distant network share. I want to choose several folders out of a directory that contains hundreds of folders ...
4
votes
4answers
2k 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 ...
4
votes
3answers
4k 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 ...
4
votes
1answer
90 views

Apache MatchRedirect exception regex

I want to redirect any URL that is Https and hasn't start with "system_" to the same URL with http. for exapmle for this url : https://exsite.tld/some/thing/that/not/start/with/pattern to : ...
4
votes
2answers
222 views

Why does a $1 backreference work in a rewrite with no subgroups?

Someone I'm working with committed a RewriteRule such as the following to SVN: RewriteRule ^admin/ebay.*$ /yii.php/$1 [L] I warned him that it may not work because there is no subgroup in the match ...
4
votes
1answer
714 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 ...
4
votes
1answer
387 views

Is it possible to get the matched regex from within the apache LocationMatch directive?

I'm wondering if the following code should be working: <LocationMatch "/(.*)([/])?(.*)"> Order allow,deny Allow from all AuthType Basic AuthName "Git" AuthUserFile ...
3
votes
2answers
3k views

Why does this regex not work on linux?

prescript: I am not sure where this question belongs i cant say it works on windows but from my understanding this regex is correct and how i would write it (except maybe the ^ at the beginning) ...
3
votes
2answers
513 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 ...
3
votes
4answers
614 views

Searching for a tail tool for Linux to colorize and suppress lines by regx?

Is there any tool that does both, colorize and filtering lines to suppress form output by regex?
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 ...
3
votes
1answer
881 views

Bash: How do I copy timestamps using touch and regex?

Since this is more of a Bash question I think this is better suited for serverfault than superuser, even though I'm talking about media files. I had to make a batch conversion of several media files, ...
3
votes
2answers
2k 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 ...
3
votes
2answers
781 views

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

What is a good bulk find / replace tool for windows? [closed]

I'm looking to find / replace in alot of files and was wondering if anybody could recommend some good tools for Windows. I'd prefer them to be free. Thanks
2
votes
2answers
188 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 --> ...
2
votes
3answers
20k views

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 ...
2
votes
3answers
219 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. ...
2
votes
1answer
98 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;} ...
2
votes
2answers
712 views

Debugging nginx URL rewrite: How do I figure out where the problem is?

I have a specific URL pattern on a site which needs to be redirected to the HTTPS version. This is a Django site; Nginx checks each URL in memcached, and if it doesn't find a cached version it proxies ...
2
votes
1answer
221 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 : ...
2
votes
1answer
131 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 ...
2
votes
2answers
2k views

Using sed to remove both an opening and closing square bracket around a string

I'm running this command in a bash shell on Ubuntu 12.04.1 LTS. I'm attempting to remove both the [ and ] characters in one fell swoop, i.e. without having to pipe to sed a second time. I know square ...
2
votes
1answer
186 views

encapsulate text in quotes with sed buffer

I need to do a search and replace to encapsulate a variable string in single-quotes (php object notation into php array notation) such that the following block: $my_trip->trip_id = ( ...
2
votes
2answers
300 views

URL rewrite on custom Wordpress site

I've been tasked with modifying an existing Wordpress site with URL rewriting. Problem is I've never done this before. I know these rules should go in a .htaccess file in root with something like this ...
2
votes
2answers
118 views

Make shortened and long urls play together on the same domain (RewriteRule)

Long story short, I want to have both example.com/aJ5 and example.com/any-other-url working together. I'm using apache and not very good at writing regex. I have already a global RewriteRule which ...
2
votes
1answer
775 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
417 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
4answers
627 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
134 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
589 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
2answers
861 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
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 ...
2
votes
2answers
63 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
753 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
2answers
596 views

Rsync and wildcards

I am trying to back up both the "Last Session" and "Current Session" files for Google Chrome in one command, but using a wildcard doesn't seem to work. I am trying with the following command rsync ...
2
votes
2answers
729 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
582 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
2answers
2k 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
1answer
298 views

Apache LocationMatch regex behaviour does not seem correct

I am using the LocationMatch directive to set headers upon matching of certain URL patterns: # 1 # Expected matches: //mysite.com/any-page-with-at-least-a-character-and-no-dot <LocationMatch ...