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.

Filter by
Sorted by
Tagged with
3 votes
1 answer
7k views

Regular expression to restrict URL in HAProxy

I had successfully restricted an URL in my web app to certain trusted IP, using below-mentioned config in haproxy config acl trusted-ip src -f /etc/haproxy/whitelist.lst acl protected-page url /...
0 votes
2 answers
6k views

Monit: use content MATCH on “check file …” if match “xxx”

I've asked this question around a week a go at StackOverflow but no answer just yet, probably is no possible but don't know where to look for that answer, I hope someone can help over here. I'm using ...
1 vote
1 answer
1k views

410 redirection for specific urls with same ending pattern

I need help redirecting some thousands old urls to 410 with regex The url pattern is as follows: https://www.example.com/mc-xxyyzz0-12 where the last three characters are always a number, a dash and ...
42 votes
5 answers
103k views

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 ...
1 vote
1 answer
2k views

Remove "public" on URL for subdirectory installation?

This is Laravel installation. Laravel has separate public directory to set as root in Nginx. In my setup, I set /var/www/web.dev/public as root. But I have many other individual installations in ...
20 votes
3 answers
69k views

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 !...
2 votes
1 answer
1k views

Which special characters work in sieve regex?

I have the Roundcube Webmail v. 1.3.1 mail client with managesieve v. 8.7 extension and want to add some regex driven actions for my mail and the only documentation I found on the regex flavour is ...
1 vote
2 answers
210 views

Wrangling sed to find and reformat login date (or, how to kill idle mosh-server processes)

I have an old method of killing idle mosh-server processes, which doesn't work on my new VPS. Here's the old method, which I run in root's crontab to clean up mosh processes that have been idle for ...
1 vote
1 answer
3k views

How can I make haproxy rewrite a url while retaining a variable that is the middle of the path?

I'm trying to redirect a url that looks like http://host/api/getThingByID/12345 to http://host/api/addr/12345/getThing Unfortunately, regsub() does not support capture groups. I was going to try to ...
4 votes
1 answer
5k views

fail2ban: regex to block \x00 requests?

Every once in a while my server goes down, and when I check my nginx logs, I usually see something like this: 78.37.54.31 - - [20/Apr/2016:20:58:51 +0300] "\x00\x00\x00TZ\x00\x00\x00\x00\x00\x00\x00\...
1 vote
1 answer
2k views

fail2ban regex matching on testing sites, but not fail2ban itself

Hi so I'm trying to match the following log line: E/Sun, 04 Mar 2018 21:40:32 +0100: Error logging in from RemoteIP: 1.2.3.4 And after many hours I've finally got a regex that works on debuggerex, ...
2 votes
2 answers
1k views

regex sieve script not matching

I have a problem on a dovecot2 mail server with a sieve script I write. The script should automatically move mail coming from a mailing list to a folder (by list name, not list id) require ["fileinto"...
2 votes
1 answer
540 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 ...
4 votes
1 answer
5k views

nginx return 301 / redirect

among all 'redirect in nginx' questions I couldn't find how to redirect (using return 301 and better no ifs) using regexps. I have a link to my website and I'd like to remove parameter a the end: ...
32 votes
2 answers
204k views

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 ...
2 votes
1 answer
1k views

Proxy websocket with parameters through proxypass/proxypassmatch without a VirtualHost

I have been trying for the longest time to proxy a websocket with it's sid variable to the localhost service, that is serving it. I have looked far and beyond for a solution (including a lot of the ...
0 votes
1 answer
650 views

Nginx: does it matter whether regular expressions are placed before or after prefix locations?

Does it matter whether you place regular expressions before or after prefix locations? Consider this configuration: server { listen 80 default_server; server_name www.example.com; root ...
0 votes
1 answer
2k views

How to match nginx location block for non-whitespace character

I'm trying to configure a workaround for google's WontFix search behavior in nginx by having a simple subfolder for my searches. So far this is what I have. location ~* ^/search/(.*\..*)$ { ...
0 votes
1 answer
104 views

Nginx: is there an advantage, real or theoretical, of using "^.+\.ext$" instead of "\.ext$" in a regular expression location block?

Is there any reason, real or theoretical, that: location ~* ^.+\.js$ { access_log off; log_not_found off; expires max; } would be preferable over: location ~* \.js$ { access_log off;...
13 votes
1 answer
8k views

Why is it unnecessary to escape "/" in Nginx regular expressions?

So I've made it a thing to finally learn about regular expressions. Normally when working with regular expressions it is necessary to escape delimiters (like "/") with a "\". But when I'm using ...
0 votes
1 answer
6k views

match special characters in url in nginx

I ran dotdotpwn to test transversal attacks on a web server using nginx/nasxi/doxsi and the only "successes" were urls that started with a question mark. No big deal since they just defaulted to the ...
0 votes
0 answers
401 views

Postfix block zip files smaller than 20kb

I am moving away form sendmail and mime-defang, my current setup rejects zip files smaller than 20kb to try and fight the spreading of ransom-ware attachments. I know its not perfect but it helps. I ...
3 votes
1 answer
355 views

Making Nginx and PHP-FPM code version agnostic

This is not a question about a current problem but more of a "preventive medicine" question: I have the following code which is part of a much larger scrip I use to rise up Nginx environments on ...
9 votes
1 answer
17k views

Show real server name in nginx logs and params passed to fastcgi?

I have configured my nginx vhosts with a regex in server_name. nginx shows the raw regex in logs and in params passed to php-fpm (I know there's $_SERVER['HTTP_HOST'] with a real value, that's not an ...
1 vote
1 answer
392 views

baffling regex issue in Exchange

I have a transport rule in Exchange 2010 which is not behaving itself, and I get berated by the EMC if I try to fix it. The objective of the rule is block any email coming from a domain with "us" at ...
0 votes
1 answer
124 views

Virtual Alias File Using Regular Expression in Exim 4.89

I would like to thank you in advance for taking my question. I am deploying a mail server using Exim, version 4.89, and would like to use a virtual alias file using regular expression to forward ...
0 votes
2 answers
1k views

In Nginx config, how to limit regex matching?

In the nginx config file for my server, I have written the following location block: location ~ /page/(?!(3/?|5/?|6/?|8/?)) { return 301 https://anothersite.com/page$is_args$args; } With this, I'...
2 votes
1 answer
2k views

Nginx local proxy - upstream wildcard?

If browsing web.dev/test2, it will look into /var/www/testsite/test2.local/public. All done through local proxy. Below rewrite running perfectly for test2 only: upstream site.local { server 127....
2 votes
0 answers
1k views

Apache RedirectMatch for SSL allowing LetsEncrypt not working

I've been trying to use Apache RedirectMatch to send most requests to SSL, but still allowing the Lets Encrypt challenge to work: RedirectMatch permanent ^/(?!\.well\-known/acme\-challenge)(.*)$ ...
0 votes
1 answer
784 views

Why does nginx select a location block with a non-matching regex? [duplicate]

In my nginx config file I have this location block (modified for debugging purposes): location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ { expires 1; log_not_found off; return 515 "...
1 vote
1 answer
448 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 ...
0 votes
1 answer
866 views

How to write regex for 'List-Unsubscribe'?

I have found that many emails that are coming in my spam contain something like this one: List-Unsubscribe: <http://blablabla.eu/ru/unsubscribe/do?hash=78943759789437589> So far I want to ...
0 votes
2 answers
1k views

Nginx Rewrite Multiple GET Variables via Subdirectory Names?

I'm currently using nginx rewrites to pass server variables. I'm able to pass a variable like this: http://example.com/test such that it passes that as: http://example.com/?p=test. I do that with this:...
0 votes
1 answer
784 views

Nginx location for sub-pages behind "?" url

I'm trying to put an htpasswd only for a group of sub-pages under this url: https://exemple.com/doku.php?id=staff So for instance this page should be include: https://exemple.com/doku.php?id=staff:...
1 vote
1 answer
227 views

Postfix MTA - Match string in header fields

I'm trying to block some spammer by filtering some fields in the mail header, but it isn't working. The spammer is adding random domains in the headers, but the "user" is always the same, like this: ...
0 votes
1 answer
469 views

How to evaluate external addresses with virtual regexp match in Postfix?

I have the following situation. I want some more specific and some more generic virtual recipients. Assume, I have a user abc and a user john. If I receive an email for abc@mydomain, I want to forward ...
1 vote
2 answers
858 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
373 views

Apache can't compile header set regex

I have a very simple thing: RequestHeader edit X-Forwarded-User CORP\\(.*) $1 Apache 2.4.18 on ubuntu says it can't compile header edit regex? How can I troubleshoot this? Or better yet, how to ...
1 vote
2 answers
1k views

How to create fail2ban filter for phpmyadmin attacks

I am trying to figure out how to create a failregex filter for fail2ban to safeguard against the attacks below. I tried the following failregex expressions but they are not matching anything from the /...
1 vote
3 answers
6k views

How do I extract the matching part of a regex on Solaris

GNU's grep has the option --only-matching, which prints just the matching region of a regular expression. I'm on a Solaris 5.10 box without any GNU tools installed, and I'm trying to achieve the same ...
6 votes
5 answers
14k views

apache locationmatch negative regex

I'm trying to expose a location through Apache. Normally, I have this block in my vhost that says <Location /> AuthType Basic AuthUserFile /web/.htpasswd AuthName "Test Site" ...
16 votes
1 answer
8k views

Ack search for literal strings [closed]

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 ...
0 votes
0 answers
647 views

POSTFIX: header_checks redirect to several mails

I have a regex rule like this: /^Subject: *SOME TEXT*/ REDIRECT [email protected], [email protected] And the receiving server interprets that as a single mail, not two and understandably throws email ...
5 votes
1 answer
7k views

Regex for multiple sshd Received disconnect from ... [preauth]

What fail2ban regex would catch logs like these? Apr 9 08:48:28 server sshd[1856]: Received disconnect from 43.255.190.117: 11: [preauth] Apr 9 09:06:05 server sshd[1936]: Received disconnect ...
0 votes
2 answers
623 views

Nginx regex not working

I'm trying to use this regex to get a different sitemap.xml per host, without the subdomain: rewrite "([a-zA-Z\d-]+).([a-zA-Z\d-]+\.([a-z]{2,3}))\/sitemap.xml" /sitemaps/$2.xml; As you can see ...
0 votes
1 answer
895 views

Exim with MySQL lookup using regular expression

I have the following working Exim4 Router: dovecot_user: driver = accept condition = ${lookup mysql{SELECT CONCAT(mailboxes.local_part,'@',domains.fqdn) AS goto FROM domains,mailboxes WHERE \ ...
0 votes
1 answer
684 views

nginx regex with capture bug

I'm trying to use regex capture functions for create an Access-Control-Origin header. So y have two main capture, one for the adress of website ( likehttp://example.com) and another for the port ...
1 vote
1 answer
1k views

Remove optional trailing slash before proxying

I would like to proxy some requests to another server, and to never send the trailing slash. I've come up with the following which is working, but is this really the best way? It feels a little bit ...
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 ~* \.(...
7 votes
2 answers
5k views

Why does this regex not work on linux?

I can't say it works on Windows but from my understanding this regex is correct and how I would write it (except maybe the ^ at the beginning) From http://www.velocityreviews.com/forums/showpost.php?...

1
5 6
7
8 9
15