Questions tagged [regular-expressions]
The regular-expressions tag has no usage guidance.
110
questions
22
votes
10
answers
24k
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
[email protected]:some-user/my-repo.git
or
https://github.com/some-user/my-repo.git
What is the best way in ...
19
votes
1
answer
591
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
14
votes
2
answers
22k
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 ...
11
votes
2
answers
43k
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.
...
9
votes
4
answers
36k
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 ...
9
votes
2
answers
14k
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
</FilesMatch&...
8
votes
2
answers
32k
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?
8
votes
1
answer
73k
views
Extracting part of the string using Ansible regex_search and save the output as a variable
I'm having a content like below inside a file.
dataDir=/var/lib/zookeeper
4lw.commands.whitelist=mntr,conf,ruok,stat
syncLimit=2
I wanted to read the value for dataDir using Ansible and set it to a ...
5
votes
2
answers
13k
views
nginx: multiple matching location blocks
I try to set max-age header directive and Content-Disposition "attachment" as follows:
location / {
# set up max-age header directive for certain file types for proper caching
location ~* \.(...
5
votes
1
answer
12k
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
...
5
votes
1
answer
13k
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 ...
4
votes
2
answers
58k
views
Redirect of all the URLs that contain 1 word in specific, but that do not contain other words
I am migrating my website to another platform, but while I finish developing all the pages of the new website, I need my users to navigate between the 2 platforms.
So I need to make a 301 redirect of ...
4
votes
2
answers
1k
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 :)
4
votes
1
answer
977
views
nginx - which way is better to redirect and why
I want to redirect from www.mydomain.com to domain.com in nginx. I search the internet and found two ways:
First way
server {
listen 80;
server_name www.domain.com;
...
4
votes
1
answer
423
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 :
http://...
3
votes
5
answers
17k
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 ...
3
votes
1
answer
2k
views
Adding Curly Braces to Map block in nginx
I am having a problem trying to get the following configuration to work. Every time I run the config test I get a failed pass. To start off let me show you a working configuration
location / {
...
3
votes
1
answer
7k
views
postfix smtp_generic_maps with regular expression
I just started playing around with sender address rewriting with postfix.
I run a server with debian-7.11 and postfix-2.9.6.
Content of /etc/postfix/main.cf:
[...]
smtp_generic_maps = hash:/etc/...
3
votes
1
answer
27k
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 ...
3
votes
2
answers
409
views
Case insensitive exiqgrep?
My mail queue is currently full of bounce messages for the same domain, but in mixed case.
I tried using exiqgrep to filter these mails from my queue, but it seems that the command is case sensitive. ...
3
votes
1
answer
4k
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 ...
3
votes
1
answer
4k
views
How can I add values to structured data with rsyslog?
Our logs are sent from our applications to rsyslog running on the same host. Rsyslog then forwards the messages to Sumo Logic.
We need to add some metadata to our log messages in the structured data ...
3
votes
1
answer
3k
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 ...
3
votes
1
answer
2k
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
1
answer
14k
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 ...
2
votes
3
answers
14k
views
RewriteCond RequestURI why RegEx doesn't work?
i have a working RewriteCond like:
RequestURL:
http://www.myserver.com/images/gallery/summer/2013/2013-07-07/thumbs/001.jpg
RewriteCond %{REQUEST_URI} !images/gallery/summer/2013/*
RewriteRule ^...
2
votes
2
answers
196
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
1
answer
501
views
How to remove mass trailing slashes(Nginx)
I need to remove mass trailing slashes, now I have
rewrite ^/(.*)/$ /$1 permanent;
So www.example.com/ becomes www.example.com.
It's good, but when I go to www.example.com/// (any amount of slashes)...
2
votes
1
answer
1k
views
postfix virtual map regular expression
I am trying to create a small virtual_alias_maps fiel for postfix-pcre:
.*@subdom\.domain\.com [email protected]
But I get this error:
warning: pcre map /etc/postfix/virtual, line 1: unknown regexp ...
2
votes
3
answers
4k
views
Regular expression in not working in dnsmasq config
I have dnsmasq version 2.66 installed on CentOS. As per release notes, dnsmasq supports regular expressions starting 2.60
I have following enty in my config file:
address=/:clients[0-9]*\.google\....
2
votes
2
answers
73
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: "~$my_document.doc"...
2
votes
2
answers
3k
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 ...
2
votes
5
answers
7k
views
cron expression to execute on the "second last working day" of the month
I need your help to contruct a cron job to run the second last working day of every month. I can do LW as shown below but i am not sure how to do second last. I need your help and advise here please.
...
2
votes
2
answers
1k
views
Finish processing rewrite directives in location and return 301
I have the following in my nginx.conf:
location ~* /collections.*?products/([^/]+)/?$ {
rewrite ^/collections.*?products/([^/]+)/?$ /$1.html;
rewrite ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3;
...
2
votes
1
answer
3k
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):.*[email protected]/ PREPEND ...
2
votes
1
answer
181
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 ...
2
votes
1
answer
550
views
Multi-line PCRE w\ lookhead, count matches
I am trying to perform a regex that matches if both the word cat AND dog are in the regex with multi-line support
matches
cat asdjfaldsfj dog
####
does NOT match
cat adfasdf8989
####
matches
dog ...
1
vote
1
answer
117
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. How ...
1
vote
2
answers
867
views
Regex works everywhere ( tried regex101 and regstorm.net) except Powershell
I have tried various different combos and already checked other similar posts, but can't find my answer. I have a .config file and I need to exclude the comments from the file when I do my search, ...
1
vote
1
answer
1k
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 ...
1
vote
2
answers
167
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
2
answers
7k
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 ...
1
vote
2
answers
617
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 ...
1
vote
2
answers
7k
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, org)...
1
vote
2
answers
432
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
1
answer
454
views
Modify puppet nodes.pp with regex based on network (facter) subnet coverage - needs peer review
For the puppet experts out there, I am trying to modify my node.pp based on the facter network.
Example, I would like to have subnets 10.10.10.0 through 10.10.10.255 and 192.168.2.0 network to get the ...
1
vote
1
answer
1k
views
Nginx rewrite rule remove subfolders
I'm trying to setup a nginx rewrite rule but can't figure out how to get it working.
I want to redirect all urls https://domainname.com/archives/year/month/date/postname to https://domainname.com/...
1
vote
1
answer
2k
views
How to using sed to change the last character from a match line
How to using sed to change the last character from a match line ?
Exemple:
/etc/network/interfaces
auto eth0
iface eth0 inet static
address 150.0.3.50
netmask 255.255.255.0
...
1
vote
2
answers
13k
views
Zabbix 2.0: Regular Expression to extract value from a String for a trigger?
I am using Zabbix 2.0.4 to monitor several Java applications. Most values are exported via JMX. One of those exported attributes is a string that is constructed like this:
[IP_1],[port_1],[ms_time_1];[...
1
vote
2
answers
6k
views
Regular expression for monitoring HTTP errors in apache logs
I'm looking for a regular expression that I can use to scan for HTTP errors in my standard apache log files.
I'm interesting in matching all lines that don't have an HTTP 200 or HTTP 204 return ...