Questions tagged [regex]

Regex (or regexp) is known as regular expression matching of patterns, strings or characters in, for example, a large text file. Questions should be tagged as such whatever the programming language involved and the tag can also apply to command-line or graphical programs that have regex plugins or some regex capability.

Filter by
Sorted by
Tagged with
6 votes
1 answer
316 views

Regular expression to match a concatenation of fixed strings, and alternative expressions

I mean to match (with ls, rm, etc.) files with names test10 to test18, test30 to test38, test22 to test23, with a single regex, in bash. I tried many variants around $ ll "test([1,3][0-8]|22|23)&...
1 vote
1 answer
57 views

How to refer to the 'found' result in Regex

Regex will find matches that satisfy the expression but are different. How to you refer to the result instance in order to append to each instance? I have created a text file by copy/paste from a ...
0 votes
0 answers
24 views

What are the regex capabilities of FocusWriter

I am trying to remove line breaks using regex \n in FocusWriter, but it isn't recognised. Does anyone know which regex capabilities FocusWriter has? I know that [1,2,3] will match 1 or 2 or 3
2 votes
1 answer
5k views

How to filter a regex (exclude special characters)

Let's say that I need to filter all my files' names that don't include special characters. ASDA123fasf - would pass asasdasd*dasd - wouldn't pass
32 votes
4 answers
16k views

sed with PCRE (like grep -P)

I am happy that grep does support Perl Compatible Regular Expressions with the -P option. Is there a reason why the tool sed does not have this feature?
0 votes
1 answer
193 views

Perl: replace literal expression and literal variable names

When I use this expression: echo '...${var}#other.([]);,=${var}#other${var}...' | perl -pe 's/\Q.([]);,=${var}\E/.([]);,=ok/' As expected, the variable ${var} is expanded to "" (empty value)...
1 vote
1 answer
71 views

What regex flavor does gedit support?

On Ubuntu 20.04, my version of gedit 3.36.2 came with a regex checkbox for Find and Replace out of the box without installing any plugins. Which regex flavor is used?
6 votes
3 answers
12k views

How to split a large file?

How can I pass all files in a list.txt which looks like file1_1.txt file1_2.txt file1_3.txt file1_4.txt to the split command (there are other txt files in the dir) and make it return the parts ...
2 votes
3 answers
3k views

Batch rename, add extra "." character at position 3 in filename, recursively

I've been struggling to make this work but I am not very good with regex. This is what I tried to do and it didn't work (after 50 minutes, still going on with no visible change): while IFS= read -r -...
2 votes
2 answers
787 views

bash: syntax error near unexpected token '|'

Once logged in, use the "Find" utility to search within the current folder for the file whose name matches the following regex pattern: lower-case letter number special character (% & # ...
1 vote
1 answer
98 views

grep PCRE still greedy

I'm searching a multi-line text file and want to match a string from a certain word until the first match of another word: start word1 word1 word1 word1 end word2 word2 word2 start word3 word3 word3 ...
0 votes
1 answer
82 views

How to extract channel names from YouTube subscription source file

I have an html source file of YouTube subscriptions, and want to extract just the /user/CHANNELNAME parts into a separate file. The source file (browser > youtube.com > subscriptions > manage ...
1 vote
1 answer
307 views

Use exact match for apt install

I want to install g++-9 but something like: sudo apt install g++-9 Interprets g++-9 as a regex (probably because there is no exact match as I don't have the toolchain PPA installed) and installs ...
5 votes
5 answers
12k views

Exclude directories from inotifywait

Doing an inotifywait to watch a directory, and trying to exclude all subdirectories from being watched while not excluding the files. inotifywait -r -q --exclude <pattern> dir/ What to put in &...
0 votes
2 answers
145 views

why grep with regex command not working on Ubuntu

I wanted to know the packages which are installed and starting with mos then below command not working. dpkg -l | grep ^mos*
0 votes
1 answer
76 views

Does grep and friends have a way to match strings as if shell file name globbing in stead of regex

Effectively I'm trying to search a text file containing "file names" and want to match as if shell file globbing were in effect. Shell file globbing is much simpler than regular expressions, ...
0 votes
1 answer
145 views

Search snaps using regex/patterns

Is it possible to narrow down the results of snap find <package>? For example, if I search for code as: snap find code can I add another keyword that should be looked at in publisher or summery? ...
0 votes
1 answer
147 views

Remove characters from file name - between [ and ]

i download videos from YouTube for my hobby. The filenames contain some random characters between the [ and ]. E.g. filename [vbnghztresku].webm. My partial solution starts as follows: find /medien -...
0 votes
1 answer
439 views

End of line in sed command

I need to append some variable string at the end of every line in the file using the sed command. Let's say that $var is a variable string. If I use a single quote sed -i 's/$/$var/' inputfile.txt --&...
2 votes
1 answer
589 views

Why "mount | grep sdb" displays no output, when "sdb" drive is a [swap] partition?

I'm learning about lsblk and mount commands in Ubuntu. I'm using Linode vps server, 2CPU, 4GB ram with 1 additional block storage volume attached. I have 2 questions related with this subject. At ...
0 votes
1 answer
248 views

Can globbing be used to search file contents?

I basically understand that globbing is used for filename expansion in the shell. I also understand that regular expressions are used for text pattern matching within a file. However, is globbing also ...
0 votes
1 answer
16 views

Need help to figure out a regex to modify some files

I have some files that I need to clean up some names. for example: GCA_940670685.1_Clostridium_sp_chr 3757330 GCA_940677205.1_Clostridium_colinum_chr 2035557 GCA_942548115.1_Aeromicrobium_sp_chr ...
3 votes
4 answers
12k views

adduser.conf NAME_REGEX is not working

I am trying to set a rule for new users. I changed the /etc/adduser.conf file by adding the line: NAME_REGEX="[A-Z]{1}[a-z]{5,9}$" but after that, the system is not accepting any user.. always ...
0 votes
0 answers
135 views

I am looking for a text editor allowing to save and edit a list of search and replace expressions (search in multiple files, a plus)

I am looking for a text editor for linux (I am using Ubuntu) that is able to save, let me edit and choose among a list of search and replace list. I have looked around and cannot find what I am ...
0 votes
2 answers
143 views

Rename files matching expression

I have to rename a lot of jpg files like Portrait_14-9-100390.jpg to Portrait-9-100390.jpg,i.e. remove _nn part. I did that with a dumb shell script : sudo rename -f -v 's/_20//' /var/www/prod/110253/...
0 votes
1 answer
161 views

Krusader quick search on Ubuntu 20.04 : What syntax to use to search for filenames with RegEx?

Installed Krusader on Ubuntu 20.04 as Nautilus dropped sorting of search results. Cant find a way (syntax) to do a QuickSearch with RegEx; I know how to write RegEx syntax, but what special character(...
5 votes
2 answers
13k views

Why am I getting the error "missing terminating ] for character class"?

I want to cut a string with brackets using sed. How to avoid an error if I want to drop a string with [? For example: $ echo '[Om/mystring' | grep -oP '(?<=[Om\\)\w+' grep: missing terminating ] ...
0 votes
1 answer
184 views

multitail regex not working

I am trying to use multitail to colorize some log files for a program I have written. I've created my own colorscheme within /etc/multitail.conf and I am able to colorize a very simple regex that ...
-3 votes
1 answer
114 views

Pattern that is not a negative integer

In bash, I can use Posix Character Class such as digit="[[:digit:]]" There are also [[:alnum:]], [[:alpha:]], [[:ascii:]], [[:punct:]] What pattern can I use to match something that starts ...
0 votes
1 answer
80 views

Bash script to automate codec installation

I recently moved from Ubuntu 20.04 to 22.04. I don't keep any media files but when I visited youtube I discovered no audio was playing. After some time I came to (guided)conclusion that I need to ...
1 vote
3 answers
423 views

Missing delimiter "^" error while using regex to match 3-character words in a string

I am having trouble coming up with the proper regular expression to match 3-character strings. I have this string: asdasa asdas asdhhgfh dfgdfdasa ttte aa1 asasda aa2 I'm trying to use regex, but can'...
1 vote
2 answers
295 views

Remove all file except multiple file by command

I have multiple file on my Ubuntu directory. I want to use a terminal command to delete all files except the files that are generated today. Today is 2019-10-15 and my files are: ... ...
1 vote
1 answer
3k views

How to validate a domain name with regex Bash script?

I'm trying to validate any domain name but it seems doesn't work the match. Don't understand why the syntax looks fine and I also verified this regex on https://rubular.com/r/QmX59URV8D It's working ...
0 votes
3 answers
112 views

While $value != [a..b]

I'm trying to write a function that rewrites a value according to a user's choice. So far it looks like this: while [[ $code_id != [1-28] ]]; do echo "Please select a value..." echo "1. ...
6 votes
1 answer
3k views

geany editor match newline

I have a plain text file with a large number of lines with a blank line between each pair of lines. I want to remove the empty lines. I am trying using the Replace dialog with regex, to replace '\n\...
0 votes
0 answers
1k views

rsync pattern to include all files of specific patterns and exclude the rest, from all subdirectory tree

I mean to rsync some files of a subdirectory tree at dir1. I am using [dir1]$ rsync --itemize-changes --recursive --update --times --include-from="rsync_include.dat" --exclude="*" -...
0 votes
1 answer
218 views

Reg ex - awk - grep from getline result [closed]

I have a expr in awk, but I can't grep the result echo 34100 | awk '{expr $1 / 33.7 | getline result;}' -> sh: 1: 1009.89: not found the calculation is ok but I need to have the 1009.89 and not ...
0 votes
1 answer
134 views

How to save specific lines of command line outputs

I have an executable that produces the following to the terminal: ---Start--- Some text More text -1. 1. 0.39 10 -199 some more text Complete ---End--- I want to write only the numerical values in ...
1 vote
0 answers
48 views

Is it possible to restrict a regular expression to a given number of characters or perform two logically AND connected tests in one regex?

I have to split a table into columns. The texts in two neighboring columns each match the expression (\S+\s+)+\s*. But sometimes, one column gets a bit larger than it should and then there is only one ...
1 vote
4 answers
5k views

Error while matching End of line with $ in Sed command

I am currently applying the below command in csh through a shell script. sed -i "s/cb $i$/cb $i $cb/" */callback_events Where: $i - Value of Variable i $cb - Value of Variable cb $ - To match the ...
1 vote
2 answers
2k views

In arbitrary line of text, how can bash extract a named value after an equal sign?

This question (How to get values after an equal sign) is basically what I want: Given a line of text, with named parameter looking syntax like color=red, using bash how can you grab that color value (...
-1 votes
3 answers
4k views

Grep and Regex: filter subdomains in a file

First of all sorry I should learn some grep and regex instead of asking that question but I have a little shortage of time for now. And I am definitely going to learn egrep eventually. So here is the ...
-2 votes
1 answer
203 views

match all the items that i have enough of to afford. simple regex

Taking a self guided linux tutorial and I keep getting hung up on this My output keeps including the "clock 15" please help #!/bin/sh #comment single RegEx to match all of the items that you ...
0 votes
1 answer
88 views

LibreOffice: indent all lines starting with italic via find/replace

I have a huge text, and I would like to indent all lines which start with italic text, via find/replace. I tried using ^ and italic via the format button, but then the search string is not found. If I ...
0 votes
1 answer
573 views

Regex to match lines that access a certain port and particular packets

New to Linux and the only way I can get this to work is by using the awk command unfortunately the main directions specify to not use awk. this is what I got #!/bin/sh #comment Write a single RegEx to ...
0 votes
1 answer
208 views

Rename using both captured groups and other variables

In this question I understood that we can only refer to captured groups in the rename command using single quotes. Is there a way to use both captured groups and other variables in the same rename ...
0 votes
1 answer
325 views

ignore python cache in Unison: ignore Path */__pycache__

Is ignore Path */__pycache__ the correct approach to ignore all python cache files from being synced with Unison? I do so by adding Path */__pycache__ in the graphical user interface. I know very ...
0 votes
1 answer
88 views

when using ?!<string> in perl regex, bash interprets it as search through command history

Simple problem but I can't fix it. I have the following perl regex: echo ... | grep -P "(?i)(v(ersion)?)\s?(?!0)\d(\.|,)\d{1,}" This is supposed to match every string that describes a ...
6 votes
5 answers
23k views

How to find all patterns between two characters?

I'm trying to find all patterns between a pair of double quotes. Let say I have a file with contents look like as following: first matched is "One". the second is here"Two " and here are in second ...
0 votes
1 answer
2k views

When piping grep after a curl request, regex works very strange

Simple problem but really weird. When I make a curl request and do ... | grep -Po "^\d+$", it returns nothing eventhough there are 400+ results that should match. See below: #example snippet ...

1
2 3 4 5
7