Questions tagged [regex]

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.

720 questions
67
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
  • 821
  • 3
  • 9
  • 8
43
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.
  • 555
  • 1
  • 4
  • 10
39
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
  • 1,042
  • 1
  • 8
  • 11
31
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
31
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
  • 591
  • 2
  • 5
  • 12
21
votes
10 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
  • 5,328
  • 19
  • 64
  • 84
20
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
  • 302
  • 1
  • 2
  • 8
20
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
  • 667
  • 2
  • 9
  • 20
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
19
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
  • 731
  • 3
  • 11
  • 24
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
  • 8
  • 18
15
votes
4 answers

nginx rule - match all paths except one

I am trying to match all paths that begin with /newsletter/ except one (/newsletter/one) with a regex. What I have so far: location ~ ^/newsletter/(.*)$ { // configuration here } This matches all the paths that begin with /newsletter/. How do I…
dasj19
  • 433
  • 1
  • 3
  • 11
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

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 doing? What does the PCRE limit recursion set to…
user101130
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 ~…
1
2 3
47 48