Solved

# Using regular expression in vi editor

Posted on 2009-04-06
1,379 Views
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:
Also tried /%i[0-9]{3} which  gave me the same response as well.
Just cant figure out how to do it.

0
Question by:Axonites

LVL 14

Assisted Solution

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

``````/[0-9]\{3\}
``````
0

LVL 40

Expert Comment

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

Morne Lategan earned 300 total points
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

### Suggested Solutions

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.