The regular-expressions tag has no wiki summary.
18
votes
1answer
415 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
5
votes
2answers
5k views
Apache 2: Negative FilesMatch / FilesNotMatch
If I want to apply a rule to only some files in apache2.conf, I can use <FilesMatch>.
For example:
<FilesMatch ".(gif|jpg|jpeg|png|mpg|avi)$">
deny from env=hotlink
...
4
votes
1answer
1k views
Powershell 2: How to strip a specific character from a body of ASCII text
I am trying to strip odd characters from strings using PowerShell. I used the following output to attempt to learn on my own:
get-help about_regular_expressions
I am trying to take a string that is ...
3
votes
2answers
390 views
Shell scripting and regex: Which one is better to match numbers, [[:digit:]] or [0-9]?
As the title suggests, which one is better to match numbers, [[:digit:]] or [0-9]?
I'm using the bash shell
Thanks :)
3
votes
1answer
174 views
Powershell deleting files with regular expressions
I have several thousand files of different revisions in a folder.
ACZ002-0.p
ACZ002-1.p
ACZ002-2.p
ACZ051-0.p
ACZ051-1.p
...
The revision is always the last digit before the dot. I need to preserve ...
2
votes
3answers
2k views
How to get all running process ids only?
I know that
ps ax
returns the pids
1 ? Ss 0:01 /sbin/init
2 ? S< 0:00 [kthreadd]
3 ? S< 0:00 [migration/0]
All I need is to clean those strings, but I ...
2
votes
2answers
4k views
grep to find files that contain a string greater than x characters long?
Is it possible to locate files in a directory that have strings (with no spaces) longer than x length?
2
votes
2answers
105 views
Display nth instance of grepped pattern
So here's my problem. I have an issue with a .csv file (Current.csv) in that there are commas randomly place throughout the data, so awk-ing the file doesn't give me constant column numbers for a ...
2
votes
2answers
201 views
Postfix header checks
How can I write regex for postfix header check to reject all the mails with X-Source-Dir having abc/def?
Is this OK?
/^X-Source-Dir:\s(.*abc\/def.*)/ REJECT due to spam:
2
votes
2answers
58 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
1answer
480 views
Postfix setting reply-to field to sender
I would like to set the reply-to field to the sender of the mail if the recipient matches some addresses. I know I could do a regular expression like this to do this
/^(To|Cc):.*foo@bar.com/ PREPEND ...
2
votes
1answer
150 views
Regular expressions and .htaccess - need help with understanding
I understand .htaccess and mod_rewrite on a fairly basic level, and have just started learning ForceType and SetHandler directives.
This is my .htaccess file for my domain, testsite1.localhost (only ...
1
vote
2answers
67 views
How to find files that don't contain a given search string
I have a command that finds all the PDF files that contain the string "Font"
find /Users/me/PDFFiles/ -type f -name "*.pdf" -exec grep -H 'Font' '{}' ';'
How can I change this command such that it ...
1
vote
1answer
92 views
Regular expressions in GREP [closed]
I have an .xml file. The tags inside are:
<Info>Product</Info>
Now, I have 20 000 tags like this in the file. One tag however, starts properly but it is missing a proper closing tag. ...
1
vote
1answer
957 views
use sed in shell script to replace IP Address in a file
I have a script that finds a string in a file replaces it with a new string.
$ sed -i 's/$old_string'/'$new_string'/g' $FILENAME
Now I need the condition to be a regular expression that also check ...
1
vote
2answers
127 views
Need help with grep urgently to comply with subpoena request
I am not a system administrator but I run a little website and today I have received a subpoena request from police, in order to comply I need to extract IP addresses from our server logs for needed ...
1
vote
2answers
111 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
424 views
Regular Expression matching in ssh config
I have a bunch of servers with the names srv1.domain.com, srv2.domain.com, ..., srv50.domain.com
I want to be able to connect to these servers by ssh srv1
I don't want to put 50 configuration ...
1
vote
2answers
1k 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
176 views
Using a regular expression (perl?) on a MySQL DB
I have a MYSQL DB and I need to do some text manipulation on one of the fields. This is a one-off, not an ongoing process.
The built in MySQL text manipulation functions will be a nightmare to do ...
1
vote
1answer
24 views
Firewall blocking files using Reg_Ex needs to be adjusted
We have security in our firewall to prevent SQL-Injection from destroying any of our content:
Name
Type
Context
Severity
Pattern
Configure
CS:select_into
signature
http-url
critical
...
1
vote
1answer
381 views
inotifywait usage and exclude
I want to monitor special path to any event of create or modified files recursively in it via inotifywait but I don't know what's my problem is.
I have some folders that I want to exclude.
watchpath
...
1
vote
3answers
188 views
Getting different values of particular variable from a file in UNIX
I have a file which I'd like to parse to extract certain values from it. I don't know what command and syntax I should use (maybe sed?).
Below are 2 sample lines which I might expect to find in the ...
1
vote
1answer
504 views
Install yum packages based on regular expression
I would like to install a batch of openoffice.org-* packages from the yum repository. The catch is that I want to exclude the dozens of openoffice.org-langpack* files when I do it. I also don't want ...
1
vote
1answer
31 views
rsync certain files, excluding the rest, ignoring .svn/ directory, recursively
I'm using rsync to copy some files from a share to another.
Recursively, I need to:
Delete files at destination that were removed from the origin
Only sync php and js files
Exclude every other file ...
1
vote
2answers
665 views
Watchguard Firewall WebBlocker Regular Expression for Multiple Domains?
I'm pretty sure this is really a regex question, so you can skip to REGEX QUESTION if you want to skip the background.
Our primary firewall is a Watchguard X750e running Fireware XTM v11.2. We're ...
0
votes
2answers
611 views
Use regular expression in definition of virtualhost
I have to define about 100 subdomain virtualhost entries in server config file . I want to know if there is any way to do it with regular expression to increase codes in apache config file?
0
votes
1answer
186 views
Redirect a url to a different server
I'm looking for a way to redirect any url I visit on my computer (Mac), say www.example1.com/a/b/[\d]+, to another url www.example2.com/a/[\d]+. I don't want this to be on the IP level, just for that ...
0
votes
3answers
240 views
grep out unique senders from a huge list of emails
I just found a huge list of emails under my user account in Centos /home/user/mail/new
I opened some of them and noticed they were sent from a particular cron job. From address is root@hostname.com. ...
0
votes
4answers
4k views
non greedy grep command on ubuntu?
I'm building a script which filters out all our translatables from our template system.
the problem i'm facing is the occasion where 2 translatables are on one line.
These are 2 example lines from a ...
0
votes
1answer
114 views
Help with regexp in <Files> tag of .htaccess
For poorly configured Apache servers you can have to do something like this to deny access to the .htaccess file:
<Files .htaccess>
order allow,deny
deny from all
</Files>
I would like ...
0
votes
1answer
91 views
nginx httpMapModule regex variables
The HttpMapModule documentation states that:
Since 1.0.4, case insensitive regular expressions can be used by prefixing the pattern with ~*.
And gives the example:
map $uri $myvalue {
/aa ...
0
votes
2answers
94 views
How to clear contents of all the files using find command
Is there an easy step to clear contents of all ".log" file using find command.
Currently i am using "echo -n > filename.log"
i have tried echo -n > /var/application-logs/*.log but it is not ...
0
votes
2answers
952 views
PowerShell Regex for validating DOMAIN\username
I have the following regexp for validating Windows usernames in a PowerShell script.
$fqusername -imatch '^\w+[\\]\w+$'
This works fine in my own environment, but I am planning on releasing it for ...
0
votes
1answer
21 views
JunOS Regular Expressions for AS Path
I want to write a regex in Juniper MX960 router for BGP including 3 AS paths with first element is constant, second and third are wildcard. I found that we can put as numbers manually like this:
...
0
votes
2answers
35 views
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.
...
0
votes
1answer
224 views
apache virtualhost: Auto subdomain with exception
I've been searching for a way to automatically redirect domains to a specific folder, and fond a good answer here on serverfault:
Apache2 VirtualHost auto subdomain. (The accepted answer)
So far ...
0
votes
1answer
269 views
Can I have IIS rewrite rules write to a file?
Extendng on my question at Is it possible to write a regular expression that catches a match that others have missed in IIS? I would like to know if I can have the rewrite rules write to a file. For ...
0
votes
1answer
530 views
Is it possible to write a regular expression that catches a match that others have missed in IIS?
I have written a list of regular expressions that currently redirect unused pages to the appropriately used pages e.g. if someone were to request abc.aspx it redirects them to home.aspx in IIS however ...
0
votes
1answer
106 views
How to redirect web request to some page with NOT condition in Apache
I want to redirect all requests for NOT(main.php) to handelrequest.php?page=[page]
So it must be something like:
RewriteRule !(main.php) handlerequest.php?page=$1
or
RedirectMatch !(main.php) ...
0
votes
0answers
36 views
Apache environmental variables in regular expressions
I use Apache environmental variables with path declarations. E.g.:
<Directory ${VHOST_PATH_DOCUMENT}/www.mydomain.com/htdocs/images/>
Can these be used within regular expressions? Something ...
0
votes
1answer
221 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:
...
0
votes
1answer
466 views
Apache mod_proxy_html Substitute: how to re-use part of regex match? (regex variables?)
Have a unique URL-rewriting situation in Apache.
I need to be able to take a URL that starts with
"\u002f[X]"
or
'\u002f[X]"
Where X is the rest of some URL,
and substitute the text
...
0
votes
1answer
53 views
Apache mod_rewrite reg expression
I have to manage a huge web site which has coded with absolute paths like:
<a href='http://www.samewebsite.net/anotherPage.cfm'>link to another page in the site.</a>
Now, as I ...
0
votes
1answer
134 views
Need regular expression + Apache help urgently!
I want staging.mywebsite.com to point to the staging virtual host, for the live I want mywebsite.com and www.mywebsite.com to point to the live one etc., and then for *(everythingelse).mywebsite.com ...
0
votes
1answer
409 views
I am trying to write an htaccess file performs authentication and redirects authenticated users to authorized directories. Can anyone help me with the condition syntax?
This is what I have so far but I can't get the RewriteCond and RewriteRule properly.
RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} (\d{3})$
RewriteRule !^%1 http://subdomain.mydomain.com/%1 ...
-1
votes
1answer
40 views
how to make regular expression for nginx rewrite
i wrote
rewrite ^/([\w_]+)/?$ /index.php?$1
btw, i wanna except /empty.
hmm..
wanna use
/alphabet -> alphabet
/emptyABC -> emptyABC
/empty -> not match
/emp -> emp
/emptAB -> ...
-2
votes
1answer
47 views
matching any part of a expression using grep
How Can I use grep so as to return me all matches for not only entire expression but also any part of the expression.
example:
grep "foobar" foo
where foo contains text foo
should give me a match
...

