Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a regular expression to remove lines without a word?

I am using textmate to edit a file. I would like to remove all the lines not containing a word. Here is an example.

apple ipad hp touch pad samsung galaxy tab motorola xoom 

How can i remove all the line not containing the word "pad", and get this result, using Regular Expression??

apple ipad hp touch pad 

Thanks all.

like image 914
Victor Lam Avatar asked Aug 11 '11 10:08

Victor Lam


People also ask

Can regex remove characters?

If you are having a string with special characters and want's to remove/replace them then you can use regex for that. Use this code: Regex.

How do you replace a word in regex?

When you want to search and replace specific patterns of text, use regular expressions. They can help you in pattern matching, parsing, filtering of results, and so on. Once you learn the regex syntax, you can use it for almost any language. Press Ctrl+R to open the search and replace pane.


1 Answers

Replace ^(?!.*pad.*).+$ with empty string

like image 54
kizu Avatar answered Sep 16 '22 19:09

kizu