[CALUG] vim regex challenge

Jim Bauer jfbauer at comcast.net
Sat Apr 4 18:15:50 EDT 2015


Try this

s/\.\d\{1,3}\.\d\{1,3}$//

Match '.', followed by 1-3 digits, followed by a '.' followed by 1-3 
digits at the end of the line.  You only need to escape the { not the }.
If you leave out the '$' it'll match and remove the first 2 octets 
instead of the last 2.


On 04/04/2015 05:46 PM, Howard L wrote:
> hello. I am trying to trim two octets of addresses in vim.
>
> eg:
> 99.198.98.8
> 99.198
>
> I've been trying things like:
> : s/\.\d.*$//g

This is matching a '.', followed by a digit (\d), followed by anything 
up to end-of-line.  The '*' is greedy so it always matches as much as 
possible.

> or
> : s/\.\d\{1,3\}.*$//g

This is matching a '.', followed by 1-3 digits, followed again by 
anything up to end-of-line.

>
> I feel like the first should work from the right to left for one octet
> but it seems to want to start at the first dot.
> The second doesn't find any match at all...
>
> Thanks, Howard();
>
> _______________________________________________
> CALUG mailing list
> CALUG at unknownlamer.org
> http://lists.unknownlamer.org/listinfo/calug
>




More information about the CALUG mailing list