Question on regular expressions in vi

Thread Solved

Join Date: Nov 2007
Posts: 20
Reputation: toucan is an unknown quantity at this point 
Solved Threads: 1
toucan toucan is offline Offline
Newbie Poster

Question on regular expressions in vi

 
0
  #1
Mar 22nd, 2009
I want to able to search for multiple words on the same line.
For example, consider the file with the following contents:

....
11. 15 18 40 53 => 16 19 41 54
12. 03 15 27 64 => 04 15 28 65
13. 25 46 47 91 => 26 47 48 92
14. 10 15 32 53 => 11 16 33 54
15. 01 12 16 73 => 02 13 17 74
....

Say I want to search for occurrences of "15" or "53" or "92" on the same line. Then the correct lines that the search should identify are line 11 and 14. I don't want line 15 to be identified because the 15 is used as a numeral for the line, not as data. Also, I don't want the search to identify data to the right of the "=>" word, so the 15 on line 12 doesn't count either.

So what I want is a query for: find all occurrences of "15" or "53" or "92" that are found between "." and "=>". As a note, the numbers are increasing order, with no repetitions, on each line between the "." and "=>", so the search condition can be refined as: find the lines that have at least one of {15, 53, 92} between "." and "=>".

What I have so far is:

/[.].*\(15\).*\(53\).*\(92\).*\(=>\)

However, with this condition all three of "15", "53", "92" have to be on the same line.

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 476
Reputation: nucleon has a spectacular aura about nucleon has a spectacular aura about 
Solved Threads: 91
nucleon's Avatar
nucleon nucleon is offline Offline
Posting Pro in Training

Re: Question on regular expressions in vi

 
0
  #2
Mar 22nd, 2009
> the 15 on line 12 doesn't count either.
There are two 15's on line 12.

You should probably post this in the Perl section.
I'd try (in Perl):
/\..*\s(15|53|92)\s.*=>/
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 20
Reputation: toucan is an unknown quantity at this point 
Solved Threads: 1
toucan toucan is offline Offline
Newbie Poster

Re: Question on regular expressions in vi

 
0
  #3
Mar 22nd, 2009
My mistake: the first 15 was supposed to be 14.

Thanks for your help.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 241
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: Question on regular expressions in vi

 
0
  #4
Mar 22nd, 2009
  1. /[.].*\(15\).*\(53\).*\(92\).*\(=>\)

This would still wouldn't give you the right answer? Its expecting all the search charcters to be in the same line. Look at nucleon post.

-ssharish
"Any fool can know, point is to understand"
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 20
Reputation: toucan is an unknown quantity at this point 
Solved Threads: 1
toucan toucan is offline Offline
Newbie Poster

Re: Question on regular expressions in vi

 
0
  #5
Mar 22nd, 2009
Actually, in vi all I need is:
/[.].*\(15\|53\|92).*[>]

I got confused because a website mentioned that to search for lines with 12 or 34, use "/\(12|34\)/".
However, it's missing a backslash in the group condition and it should have said to use "/\(12\|34\)/".
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC