Questions tagged [regex]

Also known as regular expression or regexp, a description of a set of strings, often used for searching and validating strings.

Filter by
Sorted by
Tagged with
0
votes
1answer
4 views

vim syntax file, how to mark everything after the word END as a comment?

i am writing a vim syntax file and would like to highlight everything after (but not including) the word END until the end of the file as a comment. thank you for any help!
0
votes
0answers
18 views

Sed: Perform pattern search in reverse order in a certain range and get the line number on each match

I want to search the pattern in a certain range but in reverse order. For example if I give the range say 200,250 then I want that search should be performed in reverse order means search should start ...
0
votes
1answer
25 views

How to exit `sed` after the first match?

I need to search a pattern I/f in a file between some range of lines and quit on the first match. For that I am using sed command like this sed -n '14922,28875{\|I/f|=}' file.txt It actually prints ...
1
vote
1answer
19 views

Regex: Find those html pages which does not contain this particular word on a link

I have these 2 lines on more than 3000 HTML pages: <link rel="canonical" href="https://mywebsite.com/hi/about.html" /> and <link rel="canonical" href="https://mywebsite.com/about.html" /&...
1
vote
2answers
27 views

MS Word terminate wildcard in advanced search

Is there a way to termiante the wilcard in the search, when I want to search for example for two words? Let's say I have the following words awesome mouse awful albatros awesome albatros awful mouse ...
0
votes
1answer
35 views

How can i invert my Regex matching results?

I have checked a lot of information about how can i invert my match..but unfortunatelly i coundnt be able to do it in for my problem. So..lets say i have this text : GS Sos_519 ...
1
vote
1answer
180 views

Understanding and using \& in vim search-and-replace

I have come across the following specifier for a vim pattern on http://vimregex.com/: \& -- the next line where the previously used substitute pattern matches And not quite sure what an ...
1
vote
1answer
43 views

Display dirs tree based on a file content

$ find ./ | tac ./dir1/file -> "abc" ./dir1 ./dir2/file - > "abc" ./dir2 ./dir3/file -> "xyz" ./dir3/dir3_1/file - > "abc" ./dir3/dir3_1 ./dir3 or $ tree ├── dir1 │   └── file -> "...
1
vote
0answers
20 views

Bash Tab expansion to list all executables based on regex

How can I use regex based methods to find commands available in the ${PATH}? For example when I press w and Tab switch. I get a list of all commands starting with w. I would like to list all ...
0
votes
2answers
85 views

Pattern matching in bash to use in case-statements (instead of regex)

I have coded one of my first bash scripts. My goal is to make my office "paper-free". I have a lot of scanned documents, that I want to save with the date (usually found at the top of each document) ...
2
votes
1answer
37 views

regex - replace ordered list of lines matching a string with another list

I have such confused ideas I couldn't describe well the problem synthetically, hence the title is horrible. Suggest me a better one too, while you're at it. Basically, I have two SubRip (.srt) ...
0
votes
1answer
20 views

Trying to use Sed with regex to fetch data from a log file

Hello I am experience difficulty to extract data from log file with sed -E command.I see regex is different than this I use in python. INFO [2020-05-10 17:37:34] [armada.gloge] Username [109/15654] ...
0
votes
1answer
35 views

Word: How to find all years (19xx or 20xx) ending with a closing parenthesis “)”

I'm helping someone do a two-way citation check in an academic paper. What I would like to do is use the Find function to find all instances of citations; all citations should have this format (...
1
vote
1answer
30 views

Notepad++ - Find list of acronyms in text file

I want to make list of acronyms in a text file. I tried some regex to find the list of words with all capital letters. Ex. [A-Z]+ This did not work. I also have another problem. Some acronyms do ...
-1
votes
1answer
49 views

Is Regex Coach broken when it comes to m/ multi-line?

Is Regex Coach broken when it comes to "treat string as multiple line" ? (There is another option and "treat string as single line" for 's', I think that's badly named and probably means "dot ...
0
votes
1answer
42 views

Notepad++ How to delete sections of text starting with a line containing a certain phrase

I'm trying to edit a few calibre files that have tags attached, but the tag line is not always formatted the same. Eg. div class="pcalibre1 pcalibre2 pcalibre tags-list" div class="pcalibre1 ...
0
votes
0answers
15 views

Rsync include certain files and directories but do not send directories that end up empty because of the include

This seems to be a bit of a specific question as I have found many that resemble it but are slightly different. The idea is to include certain directories from within a node_modules directory but not ...
-1
votes
0answers
6 views

php I need every line uniq by generate_string and preg_replace [migrated]

I want to replace every line by php code using preg_replace but its not giving me uniq every line. I need every line uniq <?php $permitted_chars = '...
0
votes
2answers
53 views

Replace each character of a word with line break

I want to have a line break between each character/letter of the word if the word is < Hello > I want it as H e l l o
0
votes
0answers
16 views

Sublime Text 3 - Regex Replace Using Conditional Match

In Notepad++, it is possible to use this kind of expression in the "Replace" box: (?{1}{$1}\n:) This means if first group matches, replace by first group followed by new line, else replace by empty ...
0
votes
1answer
34 views

regex - is there anyway to simplify this regex (OR)?

the basic regex is [^ ]*KEYWORD[^ ]* Keyword = freetext, I have many many keywords, so I use OR >>> "|", and repeat the regex many times in 1 line, for example: [^ ]*210[^ ]*|[^ ]*211[^ ]*|[^ ]*...
0
votes
1answer
43 views

Regex - how to delete word that contains specific keyword

I have description in many rows, for example You can see them at www.superuser.com/question/ask, but for the second opinion, you should check bowwwbowww too How to delete every word that contains ...
0
votes
1answer
27 views

regex to not match part of string

I am searching for time in multiple formats like: 1:00 pm 1 pm 10:38 am 8am 9p.m. etc... I came up with below regex: ([0-9][0-9]?)(\\:([0-9][0-9])(\\:([0-9][0-9]))?)? ?([ap]\\.?m\\.?) For example, ...
0
votes
2answers
67 views

Finding the first occurance of space to replace with a “ - ”

I am completely new to regex and I would greatly appreciate any help. I am trying to bulk rename files. File names are: 001 This is the first file.txt 002 This is the second file.txt 003 This is ...
1
vote
1answer
26 views

notepad++ regex duplicate xml text on each line

I need to process a xml file, in which a certain text has to be inserted (duplicated) - see the following, for an example: <Item Property1="..." ... PropertyN="someText"></Item> How I ...
0
votes
2answers
78 views

Find the every nth occurrence of a string

Despite the many similar questions, I am still confused. qx|o1|md|4SAK9H7DQ876CAJ943,SJT8642H2DKT2CQ76,SQ5HKT653DAJCKT52|rh||ah|Board 1|sv|0|pg|| qx|o2|md|4SKQJ7642H9DQJ8CK8,STHAK8762D74CQJ65,...
1
vote
1answer
45 views

Moving the first x characters of a filename to the end

I have a bunch of files or arbitrary length. I need to move the first 10 characters of the filename to the end to the end of the filename just before the extension. If I have to use the rename ...
0
votes
3answers
62 views

transform numbers in href tel tag

I have a directory with hundreds of phone numbers with the form "xx.xx.xx.xx.xx". where "x" are numbers from 0 to 9. Groups of 2 numbers are separated by a dot. I'm looking for a regex that would ...
1
vote
1answer
23 views

Read a file and replace dot with colon using sed command

Im trying to read and substitute period(.) with colon (:) from the below input file using sed regex expression. Can one please check and suggest me. Input File has 12.23.45 Expected is 12:34:78 ...
2
votes
1answer
26 views

Keep only the second and third words of each line in notepad++

I want to... keep the second... and third words only... I would like to keep only the second and third words and delete everything else in each line i.e want and to, the and second, third and words ...
1
vote
0answers
15 views

Unable to match start-of-line using egrep

I've the following command that works good on my macOS; git branch | egrep -v --regex "$REGEX_PATTERN" | xargs git branch -D where the REGEX_PATTERN=(develop|master|release|). When I change my ...
0
votes
1answer
24 views

Why isn't grep agreeing with other regex tools?

I am currently trying to write a grep command to find IP addresses in its input. My regex is \d+\.\d+\.\d+\.\d+ which works as expected in an online tester with all flavors of regex. Yet, when I ...
0
votes
1answer
57 views

Dealing with colon separated values when values themselves contain colons

I have got data in the following form : username:hash:email:ip but there are no delimiters for the values themselves. My problem is that when importing the data into Excel when a username contain a ...
0
votes
3answers
52 views

How to remove brackets

I have a RegEx to extract values in brackets [] from a string that actually is configured like this: [^\[]*(\[.*?\])[^\[]* $1; The upper regex give me the following output which is mostly what I ...
1
vote
2answers
43 views

How to replace “35yrs” with “35 yrs” using regular expressions?

I have a list that looks like this: 35yrs 74 yrs 40yrs 24yrs 36 yrs I want to use regular expressions (in Textmate) to make the list look like this: 35 yrs 74 yrs 40 yrs 24 yrs 36 yrs I have the ...
0
votes
2answers
18 views

How to delete text not matching regex in phpStorm

Having a JSON logfile, I want to extract the product IDs to have a clean list: {"comment": "comment.", "product":"100"} {"comment": "comment.", "product":"555"} {"comment": "comment.", "product":"100"...
2
votes
0answers
35 views

logcheck ignores one of my ignore patterns

I use logcheck for more than a decade and never had an issue. Now some messages are ignored and I just can't wrap my head around why. My ignore.d.server/_self contains: ^\w{3} [ :0-9]{11} [._[:alnum:...
0
votes
1answer
37 views

Prepending Text To Every Line Within Capture Group

What I have: X ( 1 2 3 ) BREAK Y ( 4 5 ) BREAK Z ( 6 7 8 9 ) BREAK What I'd like: X,1 X,2 X,3 Y,4 Y,5 Z,6 Z,7 Z,8 Z,9 I'd prefer to figure out how to do this using RegEx in Notepad++. As I ...
0
votes
0answers
34 views

VBA in Microsoft Word - change color of the text matching regex

I am writing a VBA script that applies the 'code comment' formatting to text in Word document. I created a custom style called "Code Snippet" with formatting similar to one in Visual Studio. The idea ...
0
votes
2answers
55 views

How to generate a Password Dictionary by Regex?

I forgot the password I used to encrypt a file, but I know the pattern of the word I used as password. I try to bruteforce the file, but it will take thousands of years to be decrypted, so the easy ...
-1
votes
2answers
30 views

How to append a group of lines after another group of lines? [closed]

How to transform this text from: Chapter 1. Horse Chapter 2. Orange Chapter 3. Computer /1 /2 /3 to Chapter 1. Horse/1 Chapter 2. Orange/2 Chapter 3. Computer/3 I'm not sure if regex is useful ...
6
votes
2answers
2k views

Regular expression ignoring 9 occurrences of a special character '|'

Need regular expression to parse a log line, I have to select data after 10th occurrences of pipe symbol | Sample log line; Info device Allow:FWD|TCP|data1|data2|data3|data4|data5|data6|data7|...
0
votes
1answer
42 views

ASK How to extract email regex using Emeditor? get email specific

example : hello this my email user1@domains.com contact me yes this my email user2@needthis.ca:contactmenow user:3:user3@needthistoo.com.au:contactme hello this is my email andre,user4@needthis.co.uk, ...
1
vote
2answers
69 views

how to extract a specific part of a string from character 7 to 17 and save it in new txt file (findstr, gnu32-sed or other tool)

How do I extract a specific part of a string from character 7 - 17 using regex via the command line? My string is ThisString and in the file data I have a lot of strings, but I need only ThisString ...
0
votes
1answer
57 views

How to substitute every opening curly brace that changes bracket balance from 0 to 1 with sed/awk?

Example input: void C::foo() { // <- this changes bracket balance from 0 to 1 if (true) { // balance is 2 after we process this bracket ... } // now it is 1 again } // now ...
1
vote
1answer
34 views

notepad++ Inverse Regex replace (all but string)

I want to delete all lines that do not contain specific words Example: .123 .keep1 .dsa .keep2 .asd Result: .keep1 .keep2 I use this regex (?!^.*SOMETEXT.*$)^.+\r?\n (And replace with nothing), ...
-1
votes
1answer
15 views

Allow only two instances of a character using RegEx

I am new to using regular expressions and I am trying to figure out something that would seem to be pretty easy. I would like to identify if a character exists only twice within a string. The ...
0
votes
1answer
46 views

How to edit a multiline pattern in bash (sed and awk are available)

So here is my very specific task. I have patterns of type .*[class|namespace|struct].* (this is one part of the pattern, to be precise), then an arbitrary amount of newlines \n or spaces ...
0
votes
0answers
24 views

Simple Batch CScript Hybrid

I'm interested in using RegExp for Batch. I put this script together: @if (@X)==(@Y) @end /* @goto :Batch setlocal disableDelayedExpansion set "infile=" set "test=%~1" if defined test ( setlocal ...
2
votes
1answer
110 views

Using grep to filter folders with numbers

I was trying to list only folders with numbers filtering an ls -1 (option -1 is list one file per line) through grep (I know find can do it too, but the sake of this example I want to stick to grep) ...

1
2 3 4 5
33