| | |
Question on regular expressions in vi
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for C
#include * append array arrays asterisks binarysearch calculate changingto char character cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fgets file fork forloop framework function functions givemetehcodez grade graphics gtkwinlinux hacking histogram homework inches include incrementoperators input intmain() iso kernel keyboard km lazy license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pdf performance pointer posix problem probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket spoonfeeding standard string student systemcall testing threads turboc unix user variable wab whythiscodecausesegmentationfault windowsapi





