Questions tagged [regular-expressions]
The regular-expressions tag has no usage guidance.
110
questions
1
vote
1
answer
152
views
Regexp in Apache 2.4 when used in HTTP_USER_AGENT var
I need to work with some user-agents in Apache 2.4. I googled a lot for examples, tried a million regex options, and it still doesn't work:
<If "%{HTTP_USER_AGENT} == '/^.*(Google|bing|Windows|...
0
votes
0
answers
167
views
Sudo validates command line arguments via regular expression incorrectly
Let's say we have two users: alex and alexa. We want to allow alex to execute htop as root in order to see disk usage stats, but we do not want them to see other users' processes which root can do. ...
22
votes
10
answers
23k
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 ...
0
votes
1
answer
53
views
Regular expression does not work in EMEditor
I have a simple Regular expression to select all text between X-Mozilla-Status and [Chat Info]. I tried it at https://regexr.com/, and it all works great. However, it can't find anything if I add it ...
0
votes
2
answers
968
views
How to escape pipeline char in Windows shell?
I need to specify a regular expression that includes | character to findstr command:
processtext.exe | findstr /R "Hello|Bye"
How do I escape it? \| does not work. Quotes fix issue with pipelining ...
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.
...
1
vote
2
answers
611
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
1
answer
2k
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
"\...
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 ^...
1
vote
1
answer
3k
views
Nginx Config Location Regex With Language Code In Url
Trying to achieve constant language code in url's 1st segment with nginx regex location configuration and could not find the correct syntax.
Necessary result:
example.com stays example.com
example....
0
votes
0
answers
189
views
Testing Regular Expressions
I am trying to learn regular expressions, and came across some examples online. Trying to put things together, I inputted this into bash
^(([a-j][a-j]?)|(3[a-j][a-j])$
It returns the following error
...
0
votes
1
answer
71
views
Postfix test: I can't forwarding outgoing emails
I am configuring a Postfix server in a test environment. It can only forward local emails. Outbound email must be redirected to /dev/null or to a local account. I found a solution on your forum but it ...
0
votes
1
answer
282
views
Postfix header_checks add X-Mailgun-Tag
I am trying to add in the postfix header_checks, using PREPEND, some X-Mailgun-Tag headers.
When using the following expressions in the header_checks, it applies without issues to all domain emails.
/^...
0
votes
1
answer
112
views
Find and Replace using Regular Expression
I try to find a way to find and replace using EMEditor and a Regular Expression. I try to applu this for the item below:
<?php
/*f04b8*/
@include "\057mn\164/r\141id\057ho\155e/\164ap\151om\...
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];[...
0
votes
0
answers
86
views
Regular expression for location with slash at the end
I have location
location ~ /(apple|club|car|fly|fitness|nivea|nesquik) {
alias /srv/static-pages/$1.html;
}
I tried
location ~ /(apple|club|car|fly|fitness|nivea|nesquik)(\/)* {
alias /srv/...
0
votes
1
answer
185
views
Regular Expression in EMEditor
I am trying to make a simple find > replace regular expression. This does work fine in https://regexr.com/ to find this comment below. However the editor I use is EMEditor that i try to make a find ...
8
votes
1
answer
69k
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 ...
0
votes
1
answer
213
views
Nginx isn't passing on the last forward slash of an arg to a script
Have an issue where nginx isn't passing on the last forward slash of an arg to a script
Example
https://xxxx.com/test_t/company/Default/icon_category/Hotel.png
Rewrite:
location / {
rewrite "^/(...
0
votes
1
answer
66
views
Regular expression to find content that is sandwitched between 2 symbols
This might have been asked before but I cant find a solution. I am looking for a simple "Regular Expressions" search pattern to find something in my PHP files.
I am looking for the following ...
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 ...
0
votes
3
answers
4k
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 working.....
0
votes
2
answers
422
views
Find with regex not working on CentOS 7 [closed]
I have problem with find and regular expression. I would like to find files in /etc, which name begin of a or b. I tried this commands:
find /etc -type f -regex '^a'
find /etc -regextype sed -regex &...
0
votes
1
answer
965
views
Why my Fail2ban regex doesn't find matches?
I have tried many regular expressions in fail2ban config, but it never return any matches.
Line example:
[2019-12-10 10:45:38] NOTICE[15077] res_pjsip/pjsip_distributor.c: Request 'INVITE' from '<...
1
vote
0
answers
1k
views
Postfix header_checks not working: Invalid preceding regular expression
I have a problem with Postfix.
Recently we are receiving mail messages with malformed "From:" headers as these:
From: "Name Surname <[email protected]>" <[email protected]>
From: "...
0
votes
1
answer
9k
views
regular expression to match condition of character if exists should always be followed by a pattern
I need a regular expression with the condition that ..if there is an occurrence of character | one time ;the pattern immediately following is ARGS or URL
For example
abcd
ab|ARGS
cd|URL
etc is ...
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\....
0
votes
1
answer
263
views
fail2ban filter for ical regex
i am trying to get a regex for an ical service on my host working without success. This is a part of the logfile:
Tue Jul 23 13:55:23 2019: ical|T720] [info ] Accepted connection from [::ffff:2.3.4....
1
vote
2
answers
932
views
regular expression that has /admin in the middle and whole string ends with specific format
I am trying to write a regular expression such as it has /admin in the middle and ends with .css or .js or other formats.
http://example.com/admin/static/style.css (SHOULD WORK)
http://example.com/...
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 ...
0
votes
0
answers
65
views
Add rule in .htacces only if domain name begins with <regular-expression>
I have to add a rule in a server that host many sites. This rule must be added only in those .htaccess files that belongs to a site with domain beggining with "dev-" or "review-".
I have this:
#!/...
2
votes
1
answer
475
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)...
3
votes
1
answer
6k
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/...
0
votes
1
answer
7k
views
Ansible replace. Replace part of the regular expresion
I create a playbook that will harden my linux servers. Part of the process is to replace the umask in the default profiles. So, I have created this task:
- name: Change the umask for default profiles
...
2
votes
1
answer
536
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 ...
2
votes
2
answers
972
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;
...
1
vote
1
answer
447
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
2
answers
856
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
votes
1
answer
195
views
validate file content with bash Regular Expressions + Linux
how to validate the following file content
that should be include single integer/float number
by bash Regular Expression or any other idea with awk/sed
cat /var/VERSION/Version_F35_project_usa
2....
0
votes
2
answers
3k
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 ...
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 ~* \.(...
0
votes
3
answers
1k
views
Logstash Grok Parsing Failed
I need to match this entry
2015/10/30 23:58:21 pid 22223 [email protected] 192.168.0.1 [p4/2012.2/LINUX26X86_64/536738] 'test-monitor show'
To match this I wrote this Regex
P4_DATE (?...
14
votes
2
answers
21k
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 ...
-2
votes
1
answer
981
views
Sed replace path for directory from special file with delimirers slash
i should change on parameter to other from template file in linux.
sed -e "s/\${dir}/<in this place i should input path, like /home/username>/" /etc/nginx/site.conf
But it does not work. How ...
4
votes
2
answers
57k
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 ...
0
votes
2
answers
2k
views
Regular expression for second and third domain level with hyphens
I have some smart script, that check name of server and get domain name. For example, i have name of server: example.ru01. I need to get: example.ru My scipt:
#!/bin/bash
hostname=example.com01
echo ...
0
votes
2
answers
1k
views
Doesn't work regular expression for domain with hyphens
I have some smart script, that check name of server and get domain name.
For example, i have name of server: example.ru01. I need to get: example.ru
My scipt:
#!/bin/bash
hostname=example.com01
echo ...
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 ...
4
votes
1
answer
974
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;
...
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?