| | |
Question on regular expressions in vi
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 20
Reputation:
Solved Threads: 1
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.
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.
C Syntax (Toggle Plain Text)
/[.].*\(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"
![]() |
Similar Threads
- multiple variables in a mod_rewrite URL string (Linux Servers and Apache)
- regular expressions (Python)
- Regular Expression Help please! (Java)
- regular expressions (C#)
- tuff question in Java (Java)
- Regular Expressions using egrep or expr (Shell Scripting)
- programing in python question (Python)
- Quick question about text processing (Shell Scripting)
- Regular Exp (Python)
Other Threads in the C Forum
- Previous Thread: sorting help
- Next Thread: Coding for DOS
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches initialization intmain() iso km license linked linkedlist linux linuxsegmentationfault list logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi





