Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to search multiple strings (Textpad)

Tags:

regex

textpad

I'm a bit new to regex and am looking to search for multiple lines/instaces of some wildcard strings such as *8768, *9875, *2353.

I would like to pull all instances of these (within one file) rather than searching them individually.

Any help is greatly appreciated. I've tried things such as *8768,*9875 etc...

like image 441
gfuller40 Avatar asked Jan 08 '14 20:01

gfuller40


People also ask

How do I search for a regular expression in TextPad?

TextPad has two types of search commands, both in the SEARCH menu: FIND and FIND IN FILES. The first is shown in Figure 1a. When working with regular expressions, make sure that the REGULAR EXPRESSION dialogue box is activated. The regex pattern is typed into the FIND WHAT box.

How do you match periods in RegEx?

Any character (except for the newline character) will be matched by a period in a regular expression; when you literally want a period in a regular expression you need to precede it with a backslash. Many times you'll need to express the idea of the beginning or end of a line or word in a regular expression.

How do I search for multiple patterns in Python?

Search multiple words using regexUse | (pipe) operator to specify multiple patterns.

How do you search for multiple words in a regular expression?

However, to recognize multiple words in any order using regex, I'd suggest the use of quantifier in regex: (\b(james|jack)\b. *){2,} . Unlike lookaround or mode modifier, this works in most regex flavours.


2 Answers

If I understand what you are asking, it is a regular expression like this:

^(8768|9875|2353) 

This matches the three sets of digit strings at beginning of line only.

like image 118
wallyk Avatar answered Sep 22 '22 21:09

wallyk


To get the lines that contain the texts 8768, 9875 or 2353, use:

^.*(8768|9875|2353).*$ 

What it means:

^                      from the beginning of the line .*                     get any character except \n (0 or more times) (8768|9875|2353)       if the line contains the string '8768' OR '9875' OR '2353' .*                     and get any character except \n (0 or more times) $                      until the end of the line 

If you do want the literal * char, you'd have to escape it:

^.*(\*8768|\*9875|\*2353).*$ 
like image 37
acdcjunior Avatar answered Sep 23 '22 21:09

acdcjunior