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
5 votes
1 answer
284 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)&...
sancho.s ReinstateMonicaCellio's user avatar
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 ...
Bfuddled2Day's user avatar
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
Tobias Carlson's user avatar
0 votes
1 answer
181 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)...
Mario Palumbo's user avatar
1 vote
1 answer
70 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?
qwr's user avatar
  • 2,802
1 vote
1 answer
95 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 ...
Adenano's user avatar
  • 13
2 votes
2 answers
777 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 (% & # ...
MICHAEL SMITH's user avatar
0 votes
1 answer
80 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 ...
Broadsworde's user avatar
  • 4,122
0 votes
2 answers
142 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*
GMudide's user avatar
  • 6,625
0 votes
1 answer
75 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, ...
VagrantPaladin's user avatar
0 votes
1 answer
145 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 -...
Bleckie's user avatar
2 votes
1 answer
569 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 ...
michal roesler's user avatar
0 votes
1 answer
401 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 --&...
vipin kumar soni's user avatar
0 votes
1 answer
247 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 ...
Grateful's user avatar
  • 139
0 votes
1 answer
15 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 ...
Paulo Sergio Schlogl's user avatar
0 votes
0 answers
132 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 ...
Earendil's user avatar
0 votes
2 answers
140 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/...
Mitsu Tomoe's user avatar
0 votes
1 answer
157 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(...
ThR's user avatar
  • 1
0 votes
1 answer
180 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 ...
JLCarveth's user avatar
-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 ...
Fatipati's user avatar
  • 371
0 votes
1 answer
144 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? ...
Abdullah's user avatar
0 votes
1 answer
78 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 ...
shahrukh's user avatar
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 ...
Bruce Q.'s user avatar
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. ...
Bruyi's user avatar
  • 9
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="*" -...
sancho.s ReinstateMonicaCellio's user avatar
0 votes
1 answer
133 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 ...
ConfusedStudent's user avatar
1 vote
0 answers
47 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 ...
Adalbert Hanßen's user avatar
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 (...
tscizzle's user avatar
  • 113
-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 ...
CryptoTrader's user avatar
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 ...
Rinke's user avatar
  • 1
0 votes
1 answer
571 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 ...
CryptoTrader's user avatar
0 votes
1 answer
207 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 ...
Pedro Miguel Silva's user avatar
0 votes
1 answer
87 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 ...
Cas's user avatar
  • 572
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 ...
Cas's user avatar
  • 572
5 votes
1 answer
2k views

Remove and replace all Slashes from Filenames recursively

I want to rename every File in a folder-subsystem that contains a slash to be replaced with an underscore Current filenames example: Hello/there.txt File/name.jpg to Hello_there.txt File_name.jpg ...
Bob Ross's user avatar
0 votes
1 answer
240 views

Itemized Meaning of the RegEx: "(/.*)?"

I am trying to determine each element of this regular expression: "(/.*)?" Here is what I have learned on my own so far: () == grouping regex together / == ??? . == equal to any one ...
TylerJGold95's user avatar
0 votes
0 answers
42 views

batch renaming all files in a folder to lowercase letters regex not working [duplicate]

I need to rename all folders and files to lowercase, I looked on this forum and found the following command find . -name * -type f -exec rename 'y/A-Z/a-z/' '{}' \; I tried this, and while the ...
Dylan Bozarth's user avatar
2 votes
2 answers
3k views

replace text with part of text using regex with bash perl

For example I have this output: string1 anynameveryveryverylong string2 string1 othernameveryveryverylong string2 I want truncate the name to the first ten characters: string1 anynamever string2 ...
Mario Palumbo's user avatar
0 votes
0 answers
37 views

A lot of errors while reinstalling MongoDB [duplicate]

I can't use MongoDB so I need to uninstall, but when I try to reinstall it, the program shows me a lot of errors in MongoDB, MySQL and also in dpkg. sudo apt-get purge mongodb-org* Reading package ...
Sirine Sinir's user avatar
3 votes
3 answers
211 views

bash perl \z doesn't work

I have this text file or sdout: text1 text2 text1 text2 text1 text2 I have this code: perl -pe "s/text2\n\z/text3/s" text.txt #Note the modifier "/s" I with \z expect him to ...
Mario Palumbo's user avatar
0 votes
2 answers
147 views

Bash command to recognize difference between variables

I am given from stdin 2 variables a name and a number given in any order. How can I identify them correctly in a bash script such that I can print them in a file in the same order(age, Name) ./a.sh ...
satalmaty 's user avatar
0 votes
1 answer
324 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 ...
Jakob's user avatar
  • 121
0 votes
3 answers
143 views

Re: How can I escape meta-characters when I interpolate a variable in Perl's match operator?

The link How can I escape meta-characters when I interpolate a variable in Perl's match operator? didn't help me. I have tried with Python: import os line='ID_SN=02 MS=DC:A6:32:7E:74:08 S=* ...
Mario Palumbo's user avatar
0 votes
0 answers
45 views

matching single and double quotes in grep using -E [duplicate]

For practicing how grep works in Ubuntu terminal, I made one .txt file: '"..asdf_-_-..34'""'"'" jd8m***ns'''_**''x;';nn*?/...; ++..++ ./,/;]_+))(+_)((*+_":|.<"{}...
saint_sharan's user avatar
0 votes
1 answer
133 views

bash perl "and" operator

with a output: apple text1 peach text2 banana text3 melon text4 For delete rows that begin with "apple" or "banana" i put: perl -pe 's/^apple.*\n|^banana.*\n//g' And output is ...
Mario Palumbo's user avatar
4 votes
2 answers
1k views

bash --> perl command: print only the replaced text

I have the file "test.txt" that contains: Val1 = '59' Val2 = '76' Val3 = '42' Val4 = '53' I with this command: perl -pe "s/^Val2 = '(.*)'/\1/" test.txt I Want: 76 But I obtain: ...
Mario Palumbo's user avatar
0 votes
1 answer
392 views

Geany find and replace characters with accent

I use Geany editor for some time, and find it very useful. However, I cannot manage to find an efficient way to replace all characters which have accents in a single action: Rubén, Éliot y el niño =&...
guyaloni's user avatar
  • 441
0 votes
0 answers
30 views

grep regular expression to remove packages [duplicate]

This is an unexpected result I get $ dpkg -l | grep linux-modules-nvidia-440-5.4.0-* rc linux-modules-nvidia-440-5.4.0-26-generic 5.4.0-26.30+2 amd64 ...
sancho.s ReinstateMonicaCellio's user avatar
1 vote
1 answer
6k views

Does grep distinguish a variable and the $ regex?

I want to grep for a variable that has the string test, but I also want to make sure that it will only find test if that is the only word on a line. So, I tried this: string=test echo "test" ...
user1046658's user avatar
1 vote
2 answers
120 views

How to sort only usb keys?

I'm on Ubuntu 20.04 what if i want to sort only the usb keys to have an output that would be like this. usb key name / size Gb / path to the usb key I tried this but I have both the hard drives and ...
kramer's user avatar
  • 113

1
2 3 4 5
7