in reply to String removal

Is this what you’re trying to do?

0:23 >perl -wE "my $s = 'xe-2/0/0.0'; $s =~ s{\..*}{}; say $s;" xe-2/0/0 0:23 >

In a regex, . matches any character (other than a newline, unless the /s modifier is used). To specifically match a dot (period, full stop, decimal point), you need to escape it: \.

Update:

I tried with K ( to keep existing and remove values after

Variable-length look-behind (using \K) could be useful if you wanted to match something specific but exclude it from the substitution. For example, to remove the dot and any characters following it, but only if the dot itself comes immediately after a digit, you could do this:

s{\d\K\..*}{}

See “Look-Around Assertions” in perlre#Extended-Patterns. But, then again, you could accomplish the same thing without \K by using a capture:

s{(\d)\..*}{$1}

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: String removal
by Anonymous Monk on Sep 16, 2015 at 01:55 UTC

    Thanks. Works great!