Reputation: 1599
Using a regular expression, I want to parse a String like "DOCID = 1234567 THIS IS TEST" and remove the remaining String after the numbers.
How can I do this using the VIM editor?
Upvotes: 1
Views: 229
Reputation: 3288
That will do the job:
:%s/\d\+\zs.*
Explanation:
%
use the whole buffer, you can omit this if you want to change current line onlys
the substitute command\d\+
match as many numbers\zs
set the start of match here.*
everything elseUpvotes: 2
Reputation: 8452
In VIM, in command mode (press ESC), write :
:s/\([^0-9]\+[0-9]\+\).*/\1/
This will do the job. If you want to do all replacement possible, then :
:s/\([^0-9]\+[0-9]\+\).*/\1/g
Upvotes: 1
Reputation: 91385
In Perl:
$str =~ s/(= \d+).*$/$1/;
In php:
$str = preg_replace('/(= \d+).*$/', "$1", $str);
Upvotes: 4