943,648 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 483
  • C RSS
Mar 22nd, 2009
0

Question on regular expressions in vi

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toucan is offline Offline
20 posts
since Nov 2007
Mar 22nd, 2009
0

Re: Question on regular expressions in vi

> 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.*=>/
Reputation Points: 163
Solved Threads: 91
Posting Pro in Training
nucleon is offline Offline
476 posts
since Oct 2008
Mar 22nd, 2009
0

Re: Question on regular expressions in vi

My mistake: the first 15 was supposed to be 14.

Thanks for your help.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toucan is offline Offline
20 posts
since Nov 2007
Mar 22nd, 2009
0

Re: Question on regular expressions in vi

  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
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Mar 22nd, 2009
0

Re: Question on regular expressions in vi

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\)/".
Reputation Points: 10
Solved Threads: 1
Newbie Poster
toucan is offline Offline
20 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: sorting help
Next Thread in C Forum Timeline: Coding for DOS





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC