Solved

Using regular expression in vi editor

Posted on 2009-04-06
3
1,396 Views
Last Modified: 2013-12-13
Hi,
I am trying to find all three digit numbers in one of my config files:
I am using the vi editor. In the command mode I tried something like this:
/[0-9]{3}, which came back with 'Pattern not found message'
Also tried /%i[0-9]{3} which  gave me the same response as well.
Just cant figure out how to do it.

Please help.
Thanks in advance
0
Comment
Question by:Axonites
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Assisted Solution

by:Deepak Kosaraju
Deepak Kosaraju earned 200 total points
ID: 24082979
I recommend to refer the following links
http://www.lagmonster.org/docs/vi.html
http://www.geocities.com/volontir/

Use following in your vi for your requirement


/[0-9]\{3\}

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24083697
you may use

/[0-9][0-9][0-9]

But this will not restrict it to 3 digits only since it will match 3 and more digits unless you have space before or after the numbers
0
 
LVL 7

Accepted Solution

by:
Morne Lategan earned 300 total points
ID: 24085163
You have 4 possible situations:

1) start of line, text followed, 3 digits, text, end of line (aaa123bbb)
2) start of line, text, 3 digits, end of line (aaa123)
3) start of line, 3 digits, text, end of line (123bbb)
4) start of line, 3 digits, end of line (123)

Use:
[^0-9]: (not a digit)
\d       : A digit
\{3\}  : repeated 3 times
^        : Start of line
$         : end of line
\|        : OR

To configure each of the 4:

1) [^0-9]\d\{3\}[^0-9] which says not-a-digit, 3 digits, not a digit
2) [^0-9]\d\{3\}$ which says not-a-digit, 3 digits, end of line
3) ^\d\{3\}[^0-9] which says start-of-line, 3 digits, not a digit
4) ^\d\{3\}$ which says start of line, 3 digits, end of line
 
Then put OR (\|) between then to say "if 1, 2, 3 or 4 is true":

/[^0-9]\d\{3\}[^0-9]\|[^0-9]\d\{3\}$\|^\d\{3\}[^0-9]\|^\d\{3\}$
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question