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

learn more… | top users | synonyms (1)

37
votes
11answers
10k views

How can I delete everything after the first column in Notepad++?

I'm trying to get rid of everything after a column in Notepad++. Column mode is not an option. Is it possible? What I have: 70.97.110.40 159 ms [n/a] 21 ...
37
votes
3answers
42k views

How to ignore certain filenames using “find”?

One of my favorite BASH commands is: find . -name '*.*' -exec grep 'SearchString' {} /dev/null \; which searches the contents of all of the files at and below the current directory for the ...
36
votes
10answers
32k views

Renaming many files in Mac OS X, batch processing

I used to rename file in Linux via a rename command: rename 's/old_pattern/new_pattern/g' *glob Is there something similar in Mac OS X (Snow Leopard)?
34
votes
6answers
34k views

use of alternation “|” in sed's regex

I am using sed, GNU sed version 4.2.1. I want to use the alternation "|" symbol in a subexpression. For example : echo "blia blib bou blf" | sed 's/bl\(ia|f\)//g' should return " blib bou " but ...
34
votes
6answers
19k views

How can I search for regular expressions within webpages using Google Chrome or IE?

How can I search for regular expressions like 'foo|bar' on webpages using Google Chrome or IE? I'm aware of the "Regular Expression Searcher" extension, but it does not work for me. (Nothing happens ...
32
votes
7answers
14k views

How to run a regex search on Google Chrome or Firefox?

How can I search for expressions like 'foo|bar' on webpages using browsers like Google Chrome or Firefox?
29
votes
4answers
22k views

Is there a linux command like mv but with regex?

For example I want to mv (.*?).sql $1.php, is there a command that lets me specify renaming patterns?
28
votes
1answer
9k views

vim delete all lines that do NOT contain a certain word

In vim I can delete all lines that contain the word "price" with this :g /price/d How can I delete all lines that do NOT contain the word "price"?
26
votes
6answers
8k views

Substitution in text file **without** regular expressions

I need to substitute some text inside a text file with a replacement. Usually I would do something like sed -i 's/text/replacement/g' path/to/the/file The problem is that both text and replacement ...
25
votes
2answers
24k views

Counting total number of matches with grep instead of just how many lines match

Does grep offer a way to count the total number of matches it makes? The -c option only returns the number of lines that matched the regex, but in this case I have multiple matches per line.
19
votes
5answers
11k views

Grep tool for XML [closed]

I am looking for a good tool to perform grep-like operations on XML - for example, extract certain attributes only. Grep itself can't handle it - any DFA-equivalent tool can handle only non recursive ...
18
votes
10answers
65k views

What regular expression can I use to match an IP address?

With the following grep syntax I want to match all IP address in a file (from a ksh script) grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file The problem: It also matches words ...
18
votes
4answers
14k views

Newlines in sed on Mac OS X

I find that \n doesn't work in sed under Mac OS X. Specifically, say I want to break the words separated by a single space into lines: # input foo bar I use, echo "foo bar" | sed 's/ /\n/' But ...
17
votes
6answers
11k views

Removing ANSI color codes from text stream

Examining the output from perl -e 'use Term::ANSIColor; print color "white"; print "ABC\n"; print color "reset";' in a text editor (e.g., vi) shows the following: ^[[37mABC ^[[0m How would one ...
15
votes
6answers
68k views

Matching only the first occurrence in a line with Regex

I am completely new to regex and I would greatly appreciate any help. The task is simple. I have a CSV file with records that read like this: 12345,67890,12345,67890 12345,67890,12345,67890 ...
14
votes
9answers
11k views

How do I copy file named starting with a dot?

I am trying to copy all files under directory A to directory B. All files under directory A are starting with dot, for example: A/.a A/.b A/.c which I found if I use: cp A/* B, always get error: ...
14
votes
2answers
18k views

How to match digits followed by a dot using sed?

I'm trying to use sed to substitute all the patterns with digits followed immediately by a dot (such as 3., 355.) by an empty string. So I try: sed 's/\d+\.//g' file.txt But it doesn't work. Why is ...
14
votes
5answers
629 views

Match and delete in Notepad++

I have the following text in Notepad++. 192.168.0.1 37 ms N/A 192.168.0.2 Dead N/S 192.168.0.3 ...
13
votes
2answers
3k views

Is there a way to search for a pattern in a MS Word document?

Is there a way to look up patterns inside an MS Word document instead of an exact match? I have a document where all decimals have been written as / instead of .. For example, 1.02 has been written ...
13
votes
1answer
12k views

How can I use newline with the Find-And-Replace in Visual Studio?

I've become rather fond of the "Find-And-Replace" function in Visual Studio. The function lets me replace phrases, words, symbols, or whatever you can type into the textbox on the screen. How can I ...
12
votes
3answers
20k views

Delete files with regular expression

I Tried to delete files that starts with A and ends with 2 numbers but It doesn't do a thing. What I tried: rm ^A*[0..9]2$ Where am I wrong?
12
votes
8answers
11k views

Notepad++ - Removing the first column in a comma separated file

I have a large CSV file that I need to remove the first column of data. I cannot open it in Excel because Excel converts some of the values in the columns to scientific numbers. I am using Notepad++, ...
12
votes
3answers
34k views

Find and Replace text between ^ and ~ in Notepad++

I have a large text file where I want to remove all text between the ^ symbol and the ~ symbol. This needs to work across lines as well. I tried doing a regular Find and Replace using ^*~ in the Find ...
12
votes
2answers
10k views

How to search for one of two similar strings in Vim?

In Vim, if I want do a search that matches "planA" or "planB", I know that I can do this: /plan[AB] This works because the regex allows for either A or B as its set of characters. But how can I ...
11
votes
4answers
38k views

Can you do Regular Expressions in Excel without VBScript?

I'm looking for an Excel function that I can put in a cell to do a regex search of the contents of another cell. Is there anything available to do this? I'd prefer not to have to add VB Script to ...
11
votes
6answers
10k views

Use Notepad++ to change under_score_case to CamelCase?

I can write a regular expression in NP++ to find under_score_case. I can use TextFX in NP++ to change case to upper and lower case by highlighting and selecting. How can I use either NP++'s ...
11
votes
5answers
2k views

Is there software to allow me to search a PDF file with Regex?

I would like a PDF viewer that I can search documents with using regular expressions. Is there such a thing? I've tried PowerGrep, but it doesn't have a graphical viewer and its interface is a little ...
10
votes
5answers
7k views

How is \$ being interpreted by grep?

When I write $ grep \$ then whatever I type on terminal, is matched and printed on terminal. How is \$ being interpreted?
10
votes
2answers
15k views

Export all regular expression matches in Textpad or Notepad++ as a list

In Textpad or Notepad++ is there an option to export all the matches for a regular expression find, as a single list? In a big text file, I am searching for tags (words enclosed in % %), using ...
10
votes
4answers
3k views

Any text editor that can apply some math to replacement text?

I have big XML file <obj param="2542"> <obj param="2333"> <obj param="6433"> I need to increase all "param" values by some number. I can match numbers that I need with regexp ...
10
votes
1answer
619 views

Why there are so many regular expression variants? [closed]

Today when I reviewed our project's source code, I found there are lots of unnecessary "spaces" and "tabs" located at each line's end. So I decided to delete them with regular expression. ...
10
votes
5answers
4k views

Can I use perl regular expressions in the vim command line?

I want to use perl regular expressions on the vim command line. For example, to capitalize the words on the current line, you could type: :s/(\w+)/\u$1/g
10
votes
1answer
3k views

How do I include newlines in a search in less?

How can I search for newlines (or end of lines) as part of a search using less? For example, I'd like to search for length=9\n, but don't want to merely search for length==9 because that'd get ...
9
votes
5answers
20k views

NotePad++ - Why does finding ^ not work?

I am trying to move away from TextPad, and I just can't get regular expressions like ^ and $ to be replaced. I have definitely ticked the regular expression box. What am I doing wrong? I am trying ...
9
votes
3answers
31k views

How to delete files on the command line with regular expressions?

Lets say I have 20 files named FOOXX, where XX is the number of the file, eg 01, 02 etc. At the moment, if I want to delete all files lower than the number 10, this is easy and I just use a wildcard, ...
9
votes
4answers
19k views

Grep multiline pattern

How do I search for a phrase over multiple lines? E.g. Lets have the phrase "my ice tea" then it may be wrapped in text files: as js skdfh dfh djh sf my ice tea. grep will not match since there is ...
9
votes
5answers
15k views

How to list all source files (*.c, *.cpp, *.h)

I'd like to find source files (*.c, *.cpp, *.h) that contain in Linux/MinGW/Cygwin, and recursively in all sub directories. My basic idea is using find and grep. However, building a regular ...
9
votes
3answers
6k views

How can I delete U+200B (Zero-width space) using sed

I have a very large file that has zero-width spaces scattered throughout. It takes too long to open and edit using vi so I'd like to delete all instances of the character using sed. The problem is, ...
8
votes
1answer
202 views

Is there a `grep`-like utility to match strings instead of lines?

I'm using grep to extract lines that match a regular expression. How to get only the matches and not the whole line?
8
votes
1answer
824 views

Is there an opposite of :g in vim?

I know how to do something to every line that matches a pattern, using :g. Is there a way to do something to every line that does not match the pattern? For example, suppose I want to delete every ...
8
votes
2answers
5k views

Is there a pattern like ^ in vim?

In Vim normal mode, the 0 command takes you to the first column on the line and ^ takes you to the logical start of line (e.g. the first non-whitespace character). In the regex world, ^ matches the ...
8
votes
2answers
4k views

Removing files matching a numeric range regular expression

I have a folder which has many files. Some of the data files are labelled 1, 2, 3, ..., 300 I want to remove these data files using the terminal. How do I do this? I want to do something like rm ...
8
votes
1answer
947 views

How to make sed omit not matching lines?

In the following example, sed matches lines starting with an a or a c and prints the first character of that line (a or c): $ echo "ag bh ci dj ek fl" | sed 's/\(a\|c\)./\1/' # Matches lines starting ...
8
votes
1answer
3k views

How do I do a block search-and-replace with Vim?

I have text in Vim hit Ctrl+V to put VIm in block mode highlight the text I want type : this gives the this prompt :'<,'> I add to the prompt my regex s/ /*/g. This leaves me with ...
8
votes
1answer
1k views

regex edit in skype?

Ok, I am not a big skype user, but I was chatting with my sister, made a typo and habitually typed tpyo s/tpyo/typo/ to my surprise it actually changed the history. I am using the linux skype ...
7
votes
14answers
1k views

Regex tool for Linux

Windows has wonderful tool working with regular expressions - RegexBuddy. It has two problems: It's commercial. It runs on Windows (Linux version no more available). What tools (except grep) you ...
7
votes
4answers
3k views

Looking for a regular expression to work on a list of comma separated values

I have line of 3 long numbers separated by comma. What I want to do is to delete the number in the middle, and leave only first number and last number separated by a comma. Currently: ...
7
votes
1answer
16k views

Find and replace in Notepad++ using wildcards/regex

I have a SQL dump with expressions such as youtubehd:2nj6bykw. The 2nj6bykw can also be a different random string. It is always 8 characters long. I want to replace youtubehd:2nj6bykw with just ...
7
votes
3answers
11k views

Grep: count number of matches per line

I'm trying to get the number of matches (in this case occurrences of { or }) in each line of a .tex file. I know that the -o flag returns only the match, but it returns each match on a new line, even ...
7
votes
2answers
4k views

Howto search in PDFs using regular expressions?

Usually I use Notepad++ to search in file(s) using regular expressions. Today I am wondering if there is a PDF program that does the same for PDFs. Of course I could convert the PDF to text and use ...