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.
Questions tagged [regex]
672 questions
58
votes
2 answers
Nginx location regex doesn't work with proxy pass
I'm trying to get these 2 location directives working in Nginx but I'm getting some errors back when booting Nginx.
location ~ ^/smx/(test|production) {
proxy_pass http://localhost:8181/cxf;
}
location ~ ^/es/(test|production)…
Niels
- 731
- 2
- 8
- 8
40
votes
2 answers
Nginx: location regex for multiple paths
I have two locations in nginx config that work:
location ^~ /media/ {
proxy_pass http://backend.example.com;
}
location ^~ /static/ {
proxy_pass http://backend.example.com;
}
How can I combine these two into one location?
What I have done…
Vlad T.
- 525
- 1
- 4
- 10
34
votes
5 answers
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 brackets have special meaning in a regex so I'm…
Xhantar
- 962
- 1
- 7
- 11
30
votes
7 answers
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 grep because it matches the whole line.
Please let me…
Alex L
- 581
- 2
- 5
- 11
29
votes
2 answers
Nginx wildcard/regex in location path
The Nginx config I have throws 404 for .php like:
## Any other attempt to access PHP files returns a 404.
location ~* ^.+\.php$ {
return 404;
}
However I have some index.php file in subfolder that I want to run. The current config is…
user156477
19
votes
2 answers
What is the difference between Nginx ~ and ~* regexes?
What is the difference between Nginx ~ and ~* regexes?
For example:
if ($http_referer ~* www.foobar.net) {
...
}
vs
if ($http_referer ~ www.foobar.net) {
...
}
PartialOrder
- 292
- 1
- 2
- 8
19
votes
1 answer
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
hortitude
- 565
- 1
- 3
- 10
16
votes
1 answer
Ack search for literal strings
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 get:
Unmatched ( in regex; marked by <-- HERE in…
tester
- 565
- 7
- 18
15
votes
6 answers
Modify fail2ban failregex to match failed public key authentications via ssh
fail2ban doesn't recognize failed public key ssh logins and I assume that this can be solved by modifying the failregex of /etc/fail2ban/filter.d/sshd.config to match the following line:
apoc
- 253
- 1
- 2
- 5
14
votes
2 answers
NGINX Proxy_Pass remove url substring
I have one NGINX acting as reverse proxy. I need to remove a substring string_1 from the URL, the rest of the URL is variable.
Example:
Origin: http://host:port/string_1/string_X/command?xxxxx
Destination:…
Pedro
- 557
- 2
- 8
- 19
14
votes
3 answers
How do I match a wildcard host in ACL lists in HAproxy?
I have the following lines in my haproxy.conf:
acl valid_domains hdr(Host) -i mysite.com images.mysite.com docs.mysite.com admin.mysite.com
redirect location http://mysite.com/invalid_domain if !valid_domains
How do I match any subdomain?
I…
Tom
- 661
- 3
- 11
- 22
14
votes
1 answer
nginx 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 what I have:
location ~…
Echo says Reinstate Monica
- 1,125
- 3
- 11
- 16
13
votes
1 answer
How do I make sec ignore a timestamp properly
I have a rule that is set up like so;
In /etc/sec/rules.d I have;
type=SingleWithSuppress
ptype=regexp
pattern=(\S+) sshd\[\d+\]: PAM \d+ more authentication failures\; logname=.* uid=.* euid=.* tty=ssh ruser=.* rhost=(.*) user=(.*)
desc=Login…
Ethabelle
- 2,022
- 14
- 20
13
votes
8 answers
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 bash to extract the repository name my-repo from any…
Justin
- 4,836
- 19
- 55
- 79
13
votes
3 answers
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 problem is that I need to append '&locale=de-de' only if it…
Sascha
- 528
- 2
- 5
- 12