Questions tagged [regular-expression]
Regular expressions are a means of matching a pattern of characters within a string.
2,848 questions
8
votes
1
answer
98
views
POSIX: Regular Expression: "\(a\(b\)*\)*\2" matches "abab"
According to chapter 9. Regular Expressions, subchapter 9.3.6 BREs Matching Multiple Characters, number "3.": "... the expression "\(a\(b\)*\)*\2" fails to match 'abab' ...&...
7
votes
2
answers
286
views
Msys2 bash rejects empty subexpression in regular expression
I'm running a reasonably up-to-date Msys2:
$ uname -a; bash -version
MSYS_NT-10.0-26100 md2syz7c 3.6.6-2369286a.x86_64 2026-01-14 12:29 UTC x86_64 Msys
GNU bash, version 5.3.9(1)-release (x86_64-pc-...
8
votes
5
answers
1k
views
sed regex to replace "aB" with "a_b"
I have text with lowercase followed by uppercase, for example:
aB
(a and B can be any letters) and I would like to change it to:
a_b
thus changing the uppercase letter of the matched text with _ and ...
0
votes
3
answers
124
views
Exclude substrings in a large string
On some linux systems the following command will output a single large string
rpm -qa --qf '%{NAME} '
For those who don't have this command it outputs values with the following pattern:
a b c d e f g
...
0
votes
4
answers
193
views
GREP Date Format from String
I'm trying to write up a script to interact with the log files of Postgres. I have a query to get the filename of the log files.
sudo -u postgres psql -tc "SELECT setting FROM pg_settings WHERE ...
3
votes
3
answers
1k
views
How do I ensure a bash script argument is a specific value?
The following script is supposed to check $1 and see if it is a specific value. It only works when one Bash [[... =~ ...]] regex check is passed in an if statement.
The error is: When more than one ...
0
votes
2
answers
105
views
How to replace all `[` and `]` in sed?
Logical way would be to use an 's/[\[\]]/_/g' regexp replace, however it does not work as intended to.
It replaces a chain of [ and ] with a single _.
$ echo 'x[]x'|sed -E -e 's/[\[\]]/_/g'
x_x
$ echo ...
0
votes
2
answers
142
views
find and regex matching behavior? Why won't 'L1[0-6].*' match "L15a" [closed]
I'm trying to understand some subtle behavior of find and its -regex option
I am trying to create symbolic links from files entitled slides_.*.pdf in folders that start with L1[0-6]. I tried the ...
1
vote
1
answer
72
views
Where can one find a repository of regex for logcheck?
I was looking at logwatch, but found that it appears to have been replaced by logcheck, and that logcheck is configured by default for just two files using various regexs to match lines in those logs.
...
3
votes
2
answers
229
views
Syntax Error on ssed for Regex Subroutine definitions
I'm stuck with this error without clue or reference how to solve it:
I have this list on text.txt
Angie Apple
Angie Banana
Angie Tomato
Angie Peach
Angie Onion
I'm running substitution through ssed (...
6
votes
3
answers
492
views
Help w/ "posix-extended" regex for 'find'
Can someone explain the issue I've described below, and perhaps suggest a resolution?
I'm trying to process a set of filenames using find. My platform is macOS (Ventura 13.7.7), and the shell is zsh ...
-1
votes
1
answer
122
views
sed: why my regex does not work correctly
So, I'm facing a curious issue with sed; I have reduced my problem down to the following. Why does
sed -e 's/\"\([^\"]*\)\">/\1/' <<< '["\{">'
return ["\{&...
-1
votes
3
answers
593
views
Perl RegEx one-liner that outputs all matches from one line of STDIN
Here is a silly example that effectively illustrates what I need:
echo '"this text", " ", "is in speech marks"' | perl -lne 'print "$1" if /"(.*?)"/'
...
2
votes
3
answers
448
views
sed: invalid usage of line address 0
I need to keep only last 30 days events in the log and remove other data.
Log has timestamp (date +%e/%b/%Y:%H:%M) and next line values like
01/Jan/2025:00:00
value1
value2
...
01/Jan/2025:06:45
...
3
votes
2
answers
230
views
Embedded special characters skewing sed output
The Issue
I've been parsing a file with sed trying to tweeze out the desired data. This has worked fine for most lines in the file but there appears to be some embedded special characters that are ...