Questions tagged [regular-expressions]
107 questions
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
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
- 5,008
- 19
- 58
- 82
10
votes
2 answers
nginx simple regex location
I need to set a location param in nginx if the first 5 digits of the url are numbers.
site.com/12345/ or site.com/12345
But I can't for the life of me seem to get the correct regular expression.
None of these work.
location ^/([0-9]) { }
location…
The Digital Ninja
- 754
- 4
- 10
- 25
9
votes
2 answers
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 does the inverse? Finds all PDF files that do not…
Slinky
- 957
- 3
- 14
- 25
8
votes
2 answers
Apache 2: Negative FilesMatch / FilesNotMatch
If I want to apply a rule to only some files in apache2.conf, I can use .
For example:
deny from env=hotlink
But is there a opposite to FilesMatch, i.e. a FilesNotMatch?
What…
BlaM
- 3,816
- 5
- 26
- 27
8
votes
4 answers
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 couldn't do it with sed because I couldn't write the proper…
Jader Dias
- 4,625
- 18
- 48
- 50
8
votes
2 answers
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?
sbuck
- 391
- 2
- 6
- 16
6
votes
1 answer
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 variable. I have written following code but…
AnujAroshA
- 193
- 1
- 2
- 7
5
votes
2 answers
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 ~*…
user1876484
- 155
- 1
- 5
5
votes
1 answer
inotifywait usage and exclude
I want to monitor special path to any event of create or modified files recursively in it via inotifywait but I don't know what's my problem is.
I have some folders that I want to exclude.
watchpath
-> folder1
-> file1
->…
sweb
- 451
- 1
- 9
- 27
5
votes
1 answer
Powershell 2: How to strip a specific character from a body of ASCII text
I am trying to strip odd characters from strings using PowerShell. I used the following output to attempt to learn on my own:
get-help about_regular_expressions
I am trying to take a string that is mostly ASCII, but that has one anomalous character…
Larold
- 802
- 4
- 13
- 21
4
votes
1 answer
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;
rewrite ^/(.*) http://domain.com/$1…
Christos Baziotis
- 303
- 1
- 4
- 14
4
votes
1 answer
Apache MatchRedirect exception regex
I want to redirect any URL that is Https and hasn't start with "system_" to the same URL with http.
for exapmle for this url :
https://exsite.tld/some/thing/that/not/start/with/pattern
to…
Arash Mousavi
- 658
- 3
- 8
- 21
4
votes
2 answers
Shell scripting and regex: Which one is better to match numbers, [[:digit:]] or [0-9]?
As the title suggests, which one is better to match numbers, [[:digit:]] or [0-9]?
I'm using the bash shell
Thanks :)
Likso
- 88
- 5
3
votes
3 answers
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 all the URLs that contain 1 word in specific, but…
Alorse
- 221
- 1
- 2
- 6