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

NGINX rewrite static to dynamic path

I am trying to rewrite a semi static URL path to a dynamic path without much luck. In full transparency, I am pretty new to NGINX and regex, so please bare with me. I am redirecting from this path: /...
1 vote
1 answer
29 views

ProxyPassMatch backreference issues

I am attempting to take all requests matching the regex ^/(map/maps/[^/]*/live/.*) redirect into a local server http://127.0.0.1:8100/. However, the path that needs to be passed to the backreference ...
0 votes
2 answers
379 views

Get the first letter of subdomain as variable

How do I get the first letter of a variable in nginx example server_name ~^(?<subdomain>\w+)\.development\.test$; location / { root /var/www/test/$subdomain.0/$...
0 votes
0 answers
22 views

Custom Fail2ban Regex not working

Using the regex filter below: [Definition] failregex = ^.*Priority: 0 ignoreregex = Fail2ban does not detect any of these log entries below. Mon Apr 1 21:11:29 2024 [] [1:1000002:1] SSH attempt [] ...
0 votes
0 answers
19 views

Correct regex to block POST request and GET request to single file in apache?

What's the correct fail2ban regex to block these kind of requests? The excerpt is from apache access.log 181.204.83.115 - - [28/Mar/2024:17:38:47 +0200] "POST /login.php HTTP/1.1" 200 11593 ...
1 vote
2 answers
5k views

kubernetes ingress replace path

I have two backend api-services: api-service-v1 api-service-v2 Both respond on "/api/" path I have this configuration running fine as a docker-compose setup where nginx service serves as a ...
16 votes
5 answers
66k views

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

nginx regex characters that require quoting?

So I was configuring nginx today and I hit a weird problem. I was trying to match a location like this: location ~ ^/([0-9]+)/(.*) { # do proxy redirects } ...for URLs like "http://my.domain.com/...
0 votes
1 answer
5k views

How I can create dynamic root path in NGINX config?

During my deployment, I create artifacts, which are folders with static files - html, css, js. And they are copied to the server in the folder /usr/share/nginx/html/${SHORT_COMMIT_HASH}. The site, ...
0 votes
1 answer
68 views

Fail2Ban RegEx works but filter does not

my plan is to ban all accesses to my webserver which repeatedly produce 404-errors and obviously do some scanning only For this I tried fail2ban-regex /var/log/apache2/otheraccess.log '^<HOST>. -...
1 vote
1 answer
454 views

Virtual domain variable in postfix/smtp_header_checks

What Postfix virtual domain variable should I use in outgoing header creation? Current server I'm running a database-driven virtual domain server managed by PostfixAdmin. I want to put statements in ...
0 votes
2 answers
179 views

Fail2Ban: RegEx to filter all 404 errors out of the Apache-log

In my logs I regularly see loads of 404-errors where bots obviously do scan the server systematically for specific software installations. As this also causes loads of traffic, I want to ban them. So ...
1 vote
1 answer
7k views

NGINX replace string in $args

I would like to manipulate a parameter when the string /static/ exists on the src $arg_param in nginx. location ~ ^/customresize.php { if($args_param4 ~ /static/){ #replace /...
0 votes
3 answers
341 views

Shell script capturing values from output of command

From a shell script, I run a ping command: ping -c4 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=34.2 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 ...
0 votes
0 answers
102 views

nginx replace given character globally in url

I have a legacy backend wich doesn't interpret url-encoded %2B as a + sign in urls like http://10.20.30.40/keyvalues?Name=foo%2Bbar%2Bbaz%2B... http://10.20.30.40/keyvalues?Name=foo%2Bbaz http://10.20....
0 votes
1 answer
86 views

How to apply multiple filters in asterisk 20.4.0 AMI interface

I just want to filter all event that contains "Event: Hangup and "Channel: PJSIP/ANCONA_UFFICIO" against an event like this: Event: Hangup Privilege: call,all Channel: PJSIP/...
0 votes
2 answers
537 views

More elegant ps aux | grep [g]rep do not work

I am running the command: ps -ef | grep [p]ts/1 The result is: root 13820 1733 0 14:19 ? 00:00:00 sshd: root@pts/1 root 13822 13820 0 14:19 pts/1 00:00:00 -bash root 15847 ...
0 votes
2 answers
253 views

IF statement based on comparison with %{REQUEST_URI} in .htaccess doesn't work

I'm trying to send a custom header for pages that start with /test-live/ The code I tried: <If "%{REQUEST_URI} =~ m#^/test-live/#"> Header always set X-Frame-Options "...
-1 votes
1 answer
316 views

Crafting regex for Fail2ban and NGINX

I'm having some trouble understanding how to craft a regex to capture probe attempts on my nginx webserver. I would like to craft a filter to catch sites hitting certain files (by name) and/or by php ...
0 votes
1 answer
599 views

Dynamically move mails into matching mailboxes with sieve fileinto regex

I'm trying to create a sieve script, which files mails into mailboxes (or sub-directories of the inbox) matching a certain subject identifier. For example if the subject includes 123 (three digits, 0-...
0 votes
1 answer
102 views

Remove trailing slash on nginx except for certaing URLs

I'm removing the trailing slash in a nginx virtual host using the following code but I would like to prevent that from happening when the url has certaing words or slusg like i.e /bar/ or /foo/ etc. ...
0 votes
0 answers
69 views

Fail2ban rule not working, nginx basic auth

I have a regexp like this that is used in my fail2ban jail ^ \[error\] \d+#\d+: \*\d+ user "\S+":? (password mismatch|was not found in ".*"), client: <HOST>, server: \S+, ...
0 votes
0 answers
27 views

libmodsecurity + owasp crs + nginx: regex for hyphen in name of a POST parameter in custom exclude rule

a paranoia_level = 3 of modsecurity forbids non-printable characters to be uploaded with POST payloads (application/x-www-form-urlencoded) in phase 2 using rule 920272 of owasp crs version 3.3.4 But, ...
1 vote
1 answer
167 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
2 answers
345 views

IIS Redirect Rule to redirect all subdomain traffic

I have this rewrite rule defined in the web.config file on my site: <rule name="RedirectWwwToNonWww" enabled="true" stopProcessing="false"> <match url="(.*...
0 votes
4 answers
6k views

Nginx URL virtual host rewrite issues with Magento e-commerce

I've been running into some problems with my URL rewrites. When I click a link in my Magento back-end it completely messes up the URL. We start with this link: http://icanttellmydomain.nl/index.php/...
0 votes
0 answers
107 views

nginx regex not matching the url

I have an issue with nginx, which after simplifying everything (just a single location directive) reduces to location ~ ^/api/pages/user/.*$ { return 200 "This is a dummy response for /api/user/...
0 votes
0 answers
186 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. ...
0 votes
1 answer
858 views

Nginx check if parameters exists and if so only allow specific values

I cant seem to find a way to limit some queries. Right now i have this if ($args ~* "(.*&)?page="){ set $wrongP W; } if ($args !~* (.*&)?page=(2|12|24)$){ set $wrongP "${...
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
480 views

Fail2ban apache2 access log regex

Can anyone help me with fail2ban regex My goal is to ban any accessing .env or .php files or any request that starts with "wp-", it is a little bit confusing and another to detect invalid ...
0 votes
0 answers
163 views

Using Rank Math REgex for subfolder redirects to home

So short summary: im a SEO specialist working on a website that has over 1000 404 pages due to a translator app. The subfolders /de/ /fr/ /es/ /en/ and URL's within the subfolder need to be redirected ...
0 votes
1 answer
55 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
1 answer
131 views

Can't get Samba smv.conf shadow copy snapprefix to recognise snaps

I'm really with this one. What I'm aiming for is that snpshots with an optional tag at the front, as well as untagged snaps are seen in windows as previous copies, e.g. file names such as: /mnt/pool1/....
0 votes
2 answers
4k views

Nginx alias and regex

i'll need a bit of help for alias on folder with nginx I have my folder www/ with the container of my site example.com and a lot of folder like client0, client1, client2... I should NOT modify www/...
0 votes
2 answers
205 views

Unable to compile regular expression in Fail2Ban

I'm trying to get this regex working in Fail2Ban: SRC=(?<ADDR>.*) DST.*(?=DPT=5003) In a regex tester it's working very fine. When testing in Fail2Ban, I get this error: ERROR: Unable to ...
0 votes
1 answer
246 views

linux fail2ban not catching auth a specific fail with postfix

I had journalctl open and noticed an offender repeatedly hitting me with auth fails in postfix. I have a standard postfix-sasl filter on by default that, to my knowledge, is working well. It wasn't ...
10 votes
5 answers
158k views

Most simple way of extracting substring in Unix shell?

What's the most simple way to extract substring on Unix shell (with regex)? Simple means: less feature less options less study Update I realized regex itself is conflicting with simplicity, and I ...
0 votes
0 answers
332 views

NGINX - How to serve file with filename that begins with the last segment of uri?

I have many PDFs in a \drawings folder on my server. The filename structure is: 8 digits, underscore, Rev level letter -- i.e. \d{8}_[A-Za-z]\.pdf. These files are organized in subfolders that match ...
0 votes
0 answers
524 views

fail2ban block plex failed login attempts

I want to ban IPs who attempt to authenticate against my public Plex instance. Im on Ubuntu and the log Im looking at is the following: /var/lib/plexmediaserver/Library/Application\ Support/Plex\ ...
0 votes
0 answers
58 views

regex puppet query syntax

I'm trying to learn how to use puppet query, but I'm finding it difficult to target a particular fact path using regex. If I use the following query, I get exactly what I'm looking for: puppet-query '...
0 votes
3 answers
3k views

Ansible match and change a bash prompt with regex

I would like to change the bash command prompt string from PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' to PS1='${debian_chroot:+($...
0 votes
1 answer
391 views

NGINX reverse_proxy with subpath and regex

I have a site running on localhost:8001 and I would like it to be accessible on different paths. I need to extract part of the path using regex. This does work: server { location /user/amy/ { ...
0 votes
1 answer
1k views

How to redirect all pages that contain a specific word using the .htaccess file

I have a bunch of indexed pages that start with the same word and they are all 404 so I want to redirect them all to the homepage of the site. The server is Apache, so I would like to use the ....
1 vote
0 answers
409 views

modsecurity regex not always matching simple rule

Im trying to create a simple modsecurity regex rule that stops processing the rules when a match is found and just returns status 200 on a POST request so that it doesnt continue and get blocked by ...
4 votes
2 answers
11k views

How to use a variable in a regular expression in nginx?

I've spent some time trying to find the answer before writing this question: I have several location blocks in my nginx config file that look like this: location ~ ^/(doc|img|bla|foo)/metadata/$ { .....
0 votes
0 answers
77 views

fail2ban regex failing to work

I am trying to create a regex for my fail2ban filter to block all IPs that get a incorrect login on a web application. The way I distinguish this is that each login generates a GET request in the ...
0 votes
1 answer
211 views

How to make an regex in Fail2ban with ip:port

First of all, English is not mu native language, so if I make a mistake don't shoot me. :) Here's my problem: when I use every thing works fine, as soon as there is a port number or a comma direct ...
0 votes
0 answers
188 views

REQENV and SETIF If statement isn't evaluating correctly

....or it is and I've missed something. So I have a website that can only be accessed via certain IPs. A new development is that I want some of the pages on the site to be open and freely available to ...
0 votes
1 answer
2k views

Nginx split the URI into variables to use on proxy_pass

I'm tring to get the URI parts to then pass it to the proxy_pass url. But I don't know about regex to do this. I need to get the first and last URI into a variables to pass it on the proxy_pass like ...

1
2 3 4 5
15