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)

34
votes
10answers
5k 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 ...
25
votes
10answers
21k 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)?
21
votes
4answers
13k 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?
20
votes
4answers
9k 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 ...
20
votes
4answers
7k views

regex search on google-chrome or firefox browsers?

How can I search for expressions like 'foo|bar' on webpages using browsers like google-chrome or firefox?
17
votes
2answers
11k 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.
16
votes
4answers
3k 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 ...
15
votes
5answers
8k views

Grep tool for XML

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 ...
14
votes
5answers
565 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
1answer
4k 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"?
12
votes
5answers
15k 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 ...
12
votes
6answers
4k 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 ...
12
votes
3answers
12k 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 ...
11
votes
7answers
32k 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 ...
10
votes
5answers
13k 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 ...
10
votes
8answers
7k 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++, ...
10
votes
4answers
6k 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 ...
10
votes
4answers
31k 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 ...
10
votes
4answers
27k 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 ...
10
votes
1answer
5k 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 ...
9
votes
9answers
6k 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: ...
9
votes
5answers
4k 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?
9
votes
2answers
10k views

How to find and replace the character “*” in excel

I am trying to find and replace the * (star, or shift+8) character in a bunch of formulas in Excel 2007. * of course matches the ENTIRE contents of the cell, which is not what I want. How do I ...
9
votes
1answer
471 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. ...
9
votes
4answers
3k 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
9
votes
5answers
832 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 ...
8
votes
3answers
14k 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 ...
8
votes
3answers
11k 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 ...
8
votes
1answer
472 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
2k 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
4answers
8k 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 ...
8
votes
1answer
2k 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 ...
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
2k 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 ...
7
votes
4answers
1k 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
176 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?
7
votes
2answers
5k views

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

This is a pretty simple regex question, I think. 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 ...
7
votes
1answer
14k 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
2answers
2k 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 ...
7
votes
1answer
145 views

Meaning of \b in .Net Regular Expressions [closed]

Microsoft has a nifty quick reference card for .Net Regular Expressions. But it seems to list \b as both matching Backspace and also matching "On word boundary". Which is it? Can \b really do both? ...
7
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 ...
6
votes
3answers
18k 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, ...
6
votes
2answers
5k 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 ...
6
votes
1answer
3k views

Regex for “or” of multiple words in grep

[Computer]$ grep "foo|bar" filename I understand the above command should return each line in filename where there exits "foo" or "bar". The man pages confirms | as the Regex or symbol and the code ...
6
votes
2answers
525 views

Is it possible to use NOT in a regular expression in TextMate?

I have a Matlab project which I'm working on in the OSX editor TextMate. I need to find all instances of a certain word, let's say it's "foo", that is not either preceded by a "." or succeeded by a ...
6
votes
3answers
3k 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, ...
6
votes
3answers
6k 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 ...
6
votes
2answers
3k views

Firefox3.5 addon for Regular Expression Search?

I've tried to look for an add-on with Firefox 3.5 which enables me to look up web page content against regex. I didn't find anything that helps, how about you? The version that I am using is Firefox ...
6
votes
3answers
7k views

Windows: File copy/move with filename regular expressions?

i basically want to run: C:\>xcopy [0-9]{13}\.(gif|jpg|png) s:\TargetFolder /s i know xcopy doesn't support regular-expression filename searches. i can't find out how to find out if PowerShell ...
5
votes
12answers
4k views

Parsing text files

I encountered a situation tonight where I wanted to parse a text file. I had a very, very long word list that contained English words delimited by lines. I wanted to get rid of every word (or line) ...