2022 Developer Survey is open! Take survey.

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

Is it possible to search snaps using regex/patterns in Ubuntu (20.04)?

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? ...
user avatar
-4 votes
0 answers
75 views

Matching colour format in bash [closed]

I have the following \033[21;41;32m and want to have a regex to matches. if [[ $1 =~ \[ ([0-9]+\;){2}[0-9]+m ]] I think the regex expression should match [0-9]+\;, then match the last number with [0-...
user avatar
  • 27
0 votes
1 answer
21 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 ...
user avatar
0 votes
1 answer
165 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 ...
user avatar
0 votes
3 answers
78 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. ...
user avatar
  • 9
0 votes
0 answers
176 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="*" -...
user avatar
0 votes
1 answer
80 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 ...
user avatar
1 vote
0 answers
27 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 ...
user avatar
1 vote
2 answers
192 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 (...
user avatar
  • 113
-1 votes
1 answer
107 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 ...
user avatar
0 votes
1 answer
37 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 ...
user avatar
  • 1
0 votes
1 answer
142 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 ...
user avatar
0 votes
1 answer
49 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 ...
user avatar
0 votes
1 answer
43 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 ...
user avatar
  • 540
0 votes
1 answer
592 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 ...
user avatar
  • 540
5 votes
1 answer
586 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 ...
user avatar
0 votes
1 answer
38 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 ...
user avatar
0 votes
0 answers
41 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 ...
user avatar
2 votes
2 answers
946 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 ...
user avatar
0 votes
0 answers
36 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 ...
user avatar
3 votes
3 answers
197 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 ...
user avatar
0 votes
2 answers
64 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 ...
user avatar
0 votes
1 answer
160 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 ...
user avatar
  • 121
0 votes
3 answers
86 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=* ...
user avatar
0 votes
0 answers
42 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*?/...; ++..++ ./,/;]_+))(+_)((*+_":|.<"{}...
user avatar
0 votes
1 answer
69 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 ...
user avatar
4 votes
2 answers
521 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: ...
user avatar
0 votes
1 answer
189 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 =&...
user avatar
  • 357
0 votes
0 answers
28 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 ...
user avatar
1 vote
1 answer
2k 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" ...
user avatar
1 vote
2 answers
73 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 ...
user avatar
  • 13
1 vote
1 answer
315 views

How to escape backticks in a .bash_aliases file?

How do I escape backticks as below: root:~# root:~# cat .bash_aliases alias clean='docker rm `docker ps -aq`' root:~# see also: https://stackoverflow.com/q/1250079/4531180 and https://...
user avatar
0 votes
1 answer
147 views

sed with parens in seach not working

I need to replace DatabaseConnection.GetConnection() with DatabaseConnection.GetConnection(_connectionString) Using grep (GNU grep) 3.1 grep GetConnection() CustomerRepository.cs yields bash: syntax ...
user avatar
6 votes
4 answers
1k views

How to use split file into two based on line start?

I have this file 1.txt: -e a b -e c d -e e f I want to split it into the following two files. 2.txt -e a -e c -e e 3.txt b d f where 2.txt contains all the lines starting with -e, and 3.txt ...
user avatar
2 votes
2 answers
1k views

Create and append key value pairs to a file of JSON objects with a regex of each JSON object value

I have a big file that contains json objects each object in a new line. File example {"Name" :"%Hana-29-Mrs-Smith","job":"engineer"} {"Name" :"%...
user avatar
  • 133
2 votes
1 answer
167 views

What does grouping in extended regular expressions mean?

I read that grouping treats an expression as a single unit. What does that mean? Furthermore, what does grep "\(grouping\)" file.txt or grep -E "(grouping)" file.txt do? I also ...
user avatar
1 vote
0 answers
87 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 ...
user avatar
  • 559
0 votes
1 answer
41 views

Change regex's result order after sed as order of ls -v

I am working on 53 xml files (az-0.xml ~ az-52.xml). And I ransed '/<loc>/!d; s/[[:space:]]*<loc>\(.*\)<\/loc>/\1/' az-*.xml > AZ to get all stuff in <loc> and merge them ...
user avatar
0 votes
1 answer
2k views

Is exclamation mark(!) included in regex or glob?

In many articles they never included '!' in glob, which is wrong. So, where does ! truly belong to ? I have used ! in glob eg. ls lis[!ta]* does this mean ! is a part of glob?
user avatar
  • 11
1 vote
2 answers
644 views

How to find a replace newline and commas in a file using regex function in gedit?

i have a text file : "postalAddress2": "Postal Address Line 2", "postalCity": "Postal City", "postalPostCode": "Postal Code", "postalState": "State", i need to remove the second column, ie, watever ...
user avatar
1 vote
1 answer
584 views

Asterisk problem with shell script

Well I have this problem. The problem is when I use an asterisk(*) as a paramenter to compare it with a regex expresion on a if statement. the regex expressions works fine until an asterisk is used. ...
user avatar
0 votes
2 answers
73 views

Reason for giving me more than 2 letters after sorting in regex

I have a text file that is named main.txt and it contains the strings: 1246 12 43 1 I have written the code: cat main.txt | egrep "[12-4]{,2}" I got the following output: 1246 12 43 1 Can you ...
user avatar
1 vote
1 answer
193 views

How to remove the first two characters of the file name when it is a hypen?

I have a bunch of mp3 files named - foo - bar.mp3. My goal is to remove the first hyphen and the first space on the terminal (Bash), which would give foo - bar.mp3. I tried it with rename 's/^..//' * ...
user avatar
  • 113
0 votes
1 answer
88 views

Regular expression help

The strings to be matched are based on length. String S should be matched iff (|S| mod 3) > (|S| mod 2) where |S| is the length of the string. I've tried to find wrt LCM but I don't know how to ...
user avatar
  • 1
2 votes
2 answers
105 views

Help with regular expression

Trying to build a regular expression that will match all strings that begin with word "med-" and end with ".opol.nei.com" like this one med-fe3-ua-kiol-33.opol.nei.com
user avatar
-1 votes
1 answer
1k views

Exclude match if there is word between two patterns

There is a file: cat file.txt dog blah crocodile blah dog blah cat blah crocodile blah dog blah crocodile blah dog blah cat blah dog blah cat blah crocodile blah dog blah crocodile blah mice blah cat ...
user avatar
  • 59
1 vote
2 answers
191 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: ... ...
user avatar
5 votes
1 answer
3k views

Find command with regular expressions

I am practicing a find command and the moment, and am curious about the usage of regular expressions in the find command(similar to grep). Does the command support it? If so, what are the options to ...
user avatar
  • 252
4 votes
1 answer
8k views

How do you match any character in bash regex?

In a bash script, why does message='123456789' echo "${message//[0-9]/*}" display ********* but message='123456789' echo "${message//./*}" displays 123456789? All the documentation I've seen ...
user avatar
  • 353
4 votes
1 answer
345 views

apt-file regex: find multiple packages at once using or

I'd like to search multiple packages at one using a regexp connecting pattern with logical or |. Assuming the two files /usr/lib/apache2/modules/httpd.exp and /usr/lib/apt/apt.systemd.daily exist: $ ...
user avatar

1
2 3 4 5 6