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)

16
votes
10answers
10k 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)?
14
votes
5answers
468 views

notepad ++ match and delete

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 ...
14
votes
5answers
6k 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 ...
12
votes
3answers
3k 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 ...
11
votes
5answers
7k 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?
11
votes
3answers
3k 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?
9
votes
5answers
8k 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
5answers
420 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
8answers
3k 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++, ...
8
votes
5answers
1k 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?
8
votes
2answers
2k 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.
8
votes
1answer
129 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
3answers
731 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 ...
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
374 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
381 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. ...
7
votes
1answer
133 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
3answers
350 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 ...
7
votes
1answer
11k 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
19k 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 ...
6
votes
7answers
3k 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: ...
6
votes
3answers
8k 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 ...
6
votes
1answer
5k 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 ...
6
votes
2answers
137 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
4k 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 ...
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
1answer
2k 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 ...
6
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 ...
5
votes
12answers
3k 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) ...
5
votes
6answers
10k 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 ...
5
votes
2answers
605 views

grep - match anything but given filetype

I want to clean out my music library so I don't get any more "search for suitable plugin" messages from Rhythmbox when it sutubles across some WMA-Relic. I have the tools, but now I want to FIND ...
5
votes
1answer
1k 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"?
5
votes
4answers
1k 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 ...
5
votes
2answers
571 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 ...
5
votes
2answers
3k 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 ...
5
votes
3answers
2k 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
5
votes
1answer
768 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 ...
5
votes
3answers
4k 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 ...
4
votes
4answers
1k 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 ...
4
votes
3answers
1k 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, ...
4
votes
2answers
555 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 ...
4
votes
3answers
11k 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 ...
4
votes
4answers
330 views

deleting folders in linux bash

i'm trying to delete in gnu/linux all folders inside another folder that start with a "." (dot), for that i'm using the find utility, this is what i have: find . -iname ^\..* -exec rm -rf {} \; but ...
4
votes
1answer
5k views

Notepad++ regex Replace, using match variables

In Notepad++, I want to perform a find-and-replace, providing a variable in the 'Replace with' field, which references a match from the 'Find what' field. Any ideas? I tried supplying (find) foo (\w) ...
4
votes
1answer
1k 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 ...
4
votes
3answers
179 views

sed: replace only the first range of numbers

Imagine I have an input file like this: INSERT INTO video_item_theme VALUES('9', '29'); INSERT INTO video_item_theme VALUES('19', '312'); INSERT INTO video_item_theme VALUES('414', '1'); And I wish ...
4
votes
2answers
3k 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 ...
4
votes
2answers
1k views

How to rename all files and directories in current folder?

I have a directory structure like this: ./ whatever/ foos_whatever.ext something/ foo/ 1.ext 2.ext another/ foo.ext I want to rename all files and directories that ...
4
votes
3answers
2k views

How to use grep to match domain names?

I have a list of urls like: hxxp://url.com/subpage.html hxxp://www.url2.com/index.php hxxp://subdomain.url3.com/somepage.php ... How can I use grep to match the domain names only? All the urls ...
4
votes
1answer
469 views

Search using regular expression in a browser?

is there a way to search within a browser (with any of them) using regular expression? Let's say I want to search for either "python" or "php" I don't want to have to do this twice. Ideally, this ...

1 2 3 4 5 9