Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [regular-expression]

Regular expressions are a means of matching a pattern of characters within a string.

4
votes
1answer
183 views

Search file name within file

Someone put a lot of malicious code onto every single wordpress instance on my server. For the second time. (At least) Every js file has been modified. There is a pattern though, the code always looks ...
2
votes
1answer
46 views

Bash: Regex for comparing file path

I want to check if an input string matches whitelisted file paths, then only I want to perform some operation. I am doing something like this path1="mydir/**" path2="mydir/testing" [ [ "$path2" =~ "...
2
votes
1answer
163 views

mosquitto bruteforce fail2ban failregex

I am trying to write fail2ban filter to block bruteforcing IP addresses which are trying to subscribe to username/password protected mosquitto service by guessing username/password combinations. On ...
2
votes
1answer
103 views

Use sed to keep only parts of a file and reorder it (based on textWrangler grep syntax)

I want to edit a file called trial.fastq with the following format: @NAME123.15.1 15 length=151 GTAGCNTACGGGAGGCAGCAGTGGGGAATTTTCC +NAME123.15.1 15 length=151 AAABB#>>AABDGCEGGGFGGGHHHGGGFHHGHH ...
2
votes
1answer
574 views

adding a regexp filter to block a subdomain and TLD in sendmail

Running Sendmail Version 8.15.2 on Fedora 24 and lots of spam is coming in from (subdomain).(manydomains).us. I'd like to add a filter like what's available in the access file to block and .us TLD's ...
1
vote
1answer
275 views

How to grep non consecutive patterns

How to grep non consecutive patterns... I run this command. grep -B 1 -A 2 "field-2-value" inputFile.txt |grep -v "field-3" which yields these 4 outputs. [field-1]xxx[/field-1] [field-2]field-...
1
vote
1answer
54 views

How to match string with regexp and conditionally do stuff with capture groups

The idea here is to change remotes from http to ssh in all git repositories find / -type d -name '.git' 2>/dev/null | xargs -I {} $SHELL -c \ 'cd $(dirname {}) && echo $(pwd) > /tmp/log....
1
vote
1answer
6k views

Ansible, attempting to get specific regex pattern to work with lineinfile module

As per my question above: "Ansible, attempting to get specific regex pattern to work with lineinfile module" Essentially, I'm trying to get it to work in a single play as opposed to 2 separate plays, ...
1
vote
1answer
944 views

LFTP exclude file extensions

I am trying to mirror directories with lftp but I don't want to download filetypes that are notoriously large like .mp4 and .swf. But I am having trouble with the regex - and seeming like the exclude-...
1
vote
1answer
352 views

Find & replace image URLs in one file from another file

I am trying to replace all the image source URLs in an HTML file from a list of URLs in a text file. File1.html <td class="MetadataRes" width="380px" colspan="2" style="border-top: 1px #336699 ...
0
votes
1answer
20 views

Change hostname in tnsnames.ora file

I'm trying to write a script to update just the hostname in the tnsnames.ora file. I'm needing the entry to work case insensitive. For example ${DBNAME} is lowercase database name and in my tnsnames....
0
votes
1answer
22 views

Trying to parse a string in BASH for [ - _ ]

I have a BASH script that allows a user to specify a jobname. Right now we except everything. We feed this jobname into another executable that can only accept the following formats: job_name, ...
0
votes
1answer
14 views

sed: Change a variable-length numerical value for an indeterminate string

The string I need to modify in a hardware driver .conf file is as follows: options rsi_sdio dev_oper_mode=13 Looks simple enough, but the developers are happy to change this string which will break ...
0
votes
1answer
28 views

Use sed to append data BEFORE a closing double quote encasing a Path

I need to append the path /opt/dell/dcc of an application outside of the default path statement in /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/...
0
votes
1answer
41 views

Grep: Find 3 consecutive char and then follow another char or end of the line

I want to find 3 consecutive characters and then another character or the end of the line. I tried this: egrep '(.)\1{2}' file but I need less results.
3
votes
0answers
61 views

Renaming files with vidir (moreutils)

I'm trying to use vidir from the moreutils package and I have the following issue: When I load the files I want to rename with vidir like this: $ vidir or like this: $ find -type f | vidir --...
3
votes
0answers
170 views

How do backreferences slow down regular expression search?

Let's say I have a text file with 20 chars per line like this: wertzuiopasdfghjkl< asdfghjkl<yxcvbnm,.- <yxcvbnm,.-123456789 1234567890QWERTZUIOP QWERTZUIOPASDFGHJKL< and so on ... and ...
3
votes
0answers
790 views

what is the correct regexp for mysql filter in fail2ban?

I use the default filter file /etc/fail2ban/filter.d/mysqld-auth.conf for fail2ban service. But there are some errors in file /var/log/fail2ban.log as: Found a match for '150815 10:42:54 [Warning] ...
2
votes
0answers
28 views

Interpolated and literal Perl strings in Nano are incorrectly highlighted

I am trying to improve Nano's syntax highlighting for Perl, but I have run into an interesting dilemma. Perl uses single quotes for literal strings, and double quotes for interpolated strings. The ...
2
votes
0answers
174 views

wget regex options ignored over ftp

Wget specifies the --accept-regex and --reject-regex options for limiting recursive downloads. I'm unable to get them to work with an ftp connection. For example, I would expect --reject-regex='.*' ...
2
votes
0answers
337 views

convert attachments of type winmail.dat (TNEF) to “real” attachments in stored email messages, recursively in MailDir

Some email messages contain the attachments in a format called TNEF (Transport_Neutral_Encapsulation_Format). This attachment is usually called winmail.dat. Extraction tools exist for linux, but ...
2
votes
0answers
181 views

What is SELinux's regex type?

I'm trying to locate all files on my system matching an SELinux file context (fcontext). These contexts are specified using some regex, and I'd like to use find -regex ... to the same effect. However, ...
1
vote
0answers
15 views

Find + regex: looking for a file name with multiple extensions, but missing the basic filename.jpg

I'm both a regex & SE Unix and Linux newbie, so I hope I'm doing everything right. I'm looking for files that have a name inside of the filename, and could have different extensions. I based my ...
1
vote
0answers
22 views

Regex matching comma-separated list of values, trailing comma not allowed

I want to match: aaa aaa,bbb aaa,bbb,ccc But not a list with a trailing comma. My current regex: (\w{3},?)+ also matches lists with trailing commas (aaa,bbb,). I was thinking I could also do: (\w{...
1
vote
0answers
60 views

sed command is replacing the replaced text?

I am writing a bash script to rename icons. Specifically I am trying to change "icon-close-m" to "icon-close icon-size-medium" in HTML files. (though it could contain any substring besides "close", as ...
1
vote
0answers
88 views

How to improve this 'sed' search & replace command?

How to search and replace recursively through multiple files in a directory, using essential tools installed in mostly any Debian/Ubuntu machine? There are multiple answers in Stack* where to find ...
1
vote
0answers
79 views

Sqlite: replace a string modelID1/modelID2/modelID3 with name1/name2/name3/

My goal is to read the macOS Photos.app database to find out the paths of the included photos. The album and the parent folder whose name is in the RKFolder table can be determined for each photo. ...
1
vote
0answers
27 views

How to search email with Jämsä for Jämsän in Thunderbird?

Finnish language has many many endings, but I cannot search easily the base word, etc by Jämsä. For instance, searching Jämsä will not give Jämsän in the basic Thunderbird search. A basic regex ...
1
vote
0answers
893 views

Gedit: How to insert backslash \ in search and replace regex

I'm trying to comment out some lines in c++ by matching them with a regex, and replacing with the match preceeded by \\. But instead, gedit performs no replacement, and the search+replace dialog gives ...
1
vote
0answers
175 views

Apache redirect rule using regex

Hello I am trying to do a regular expression for an apache rewrite rule that handle request with no slash at the end and no extension an example https://www.some.thing.com/life-health-insurance ...
1
vote
0answers
71 views

Emulating git status --ignored in non-repository folder

This might be in essence a duplicate of this question, however the perl script provided did not work in my case as far as I can tell. There are also many questions about finding multiple patterns, but ...
1
vote
0answers
1k views

how to exclude range of numbers using regular expression

I'm trying to write a regular expression in order to cover all numbers starting with 1809 and excluding some ranges: Ranges needed to be excluded Starting with 1809 and followed by: 201,203,205,212,...
1
vote
0answers
294 views

Need .htaccess Rewrite Rule To Remove Trailing <br%20/>

I have links that for some reason have a trailing <br%20/> and I don't know where they are coming from to try and fix them. So I need a general rewrite rule to remove them so the links won't ...
0
votes
0answers
16 views

regular expression for replacing group content using sed or perl

Have files in multiple directories that needs to match and parse each stanza and modify the existing index name into andindex=secure_pr. Also i run the script to locate the inputs file in each ...
0
votes
0answers
37 views

RegEx for replacing capturing group content using sed

Have inputs.conf files in multiple directories that needs to match and parse each stanza and modify the existing index name into index=secure_np and index=secure_pr. Also i run the script to locate ...
0
votes
0answers
23 views

Bash-Perl Make Substitution and Return array (string & number of replacements/substitutions)

I have this code that makes substitutions in a file segment. The code should be left mostly unharmed except for this problem. I need to return back to bash, the number of replacements made by perl ...
0
votes
0answers
80 views

build regexp that does not depend on the order of input data

In my script I'm dumping some out some data and grep with regular expression rules, which assume that the data come in certain order. However I've found that the order of data may vary. So instead of:...
0
votes
0answers
37 views

sed command to insert between two strings that are returned from another sed command

I have a YAML file that's about 25K lines and I have about 450 instances where I need to insert between two specific lines. Here's an example of the file entries: - changeSet: id: ...
0
votes
0answers
36 views

Commenting out a specific host configuration in a Nagios configuration file

I have lots of Nagios configuration files like the one below in a directory, and I need to remove a host from monitoring. define host{ host_name nmo use aix-server alias hostgroups +...
0
votes
0answers
54 views

Remove all words from a file except certain words

I have a file which represent a list of SQLs where caluses. I want to remove everything that is not the columns names, and, or and where(case insensitive). In addition if it can also remove new lines ...
0
votes
0answers
57 views

Change text color in PDF files

I want to change some Text-Coloring by regex search in one or more PDFs. for example i want to change the color of all appearances of "A[0-9]+.[0-9]" like A120.1, A600.0 and so on. is it even possible ...
0
votes
0answers
40 views

How can I regex match-and-replace _all_ on-screen text?

I need a way to replace an on-screen pattern with another string, regardless of what places that text on the screen. Maybe I can live without user input being replaced, but anything that comes from ...
0
votes
0answers
136 views

Why does fail2ban not trigger my custom filter?

fail2ban-regex verified that my filter matches Jan 14 07:39:41 myhost01 sshd[26433]: Connection closed by authenticating user root 127.0.0.1 port 56216 [preauth] 68 times inside auth.log, but fail2ban-...
0
votes
0answers
26 views

How to create a regex matching a custom string at the beginning of line while ignoring all preceding whitespaces via ag silversearcher?

Give an example file with the content: // find me val ignore me = "" // I should not be found // find me // find me I want to find all the lines with find me using ag silversearcher. ...
0
votes
0answers
24 views

How to iterate pattern by other one?

I have the bellow output. I try to iterate same times the Date and Time: Month Day Year HH:MM:SS for each Application n.n string found it. =========================================================...
0
votes
0answers
103 views

How to configure which characters are allowed in CentOS usernames

In systems such as Debian, there is a file /etc/adduser.conf which includes directive NAME_REGEX that can be used to define which characters are allowed in a username. Is there a way to do this in ...
0
votes
0answers
107 views

Removing lines from file matching 2 strings

I am trying to remove lines in a file that contain 2 strings. I am using: perl -i.tmp -ne "print unless /$STRING_A/ and /$STRING_B/" /foo/bar/file.txt The result is that all lines from the file ...
0
votes
0answers
159 views

Finding word with centain length containing characters from interval

I am trying to print all words that are 3 chararcers long and those characters are from [a-s] interval. I have tried following grep '\<[a-s]\{3\}\>' file.txt which outputs nothing , i have ...
0
votes
0answers
167 views

swap strings of text inside vim using regex

I am working with a file where I need to swap "string A" and "String B's" locations simultaneously with a regex inside the vim. Here is an example line of code: succ_1st=`grep 'resulted in successful ...
0
votes
0answers
73 views

Regex for a non-fixed pattern

I am trying to come up with the right regex (compatible with python) that would match a file that contained sample input as follows: On the third day of Christmas my true love sent to me: three ...