Solved

Using regular expression in vi editor

Posted on 2009-04-06
3
1,399 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

621 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