Skip to content

Regular expressions & sub

5 messages · Tony Plate, Dirk Eddelbuettel, Peter Dalgaard +1 more

#
Dear all,

I am struggling with the use of regular expression. I got
[1] "1.11"   "10.11"  "11.11"  "113.31" "114.2"  "114.3"  "114.8"  

and need

[1] "11"   "11"  "11"  "31" "2"  "3"  "8"

I.e. remove everything before the "." .

TIA,

Bernd
#
Read 7 items
 > x
[1] "1.11"   "10.11"  "11.11"  "113.31" "114.2"  "114.3"  "114.8"
 > gsub("[0-9]*\\.", "", x)
[1] "11" "11" "11" "31" "2"  "3"  "8"
 >
Bernd Weiss wrote:
#
Bernd Weiss <bernd.weiss <at> uni-koeln.de> writes:
Define the dot as the hard separator, and allow for multiple digits before it:
[1] "11" "11" "11" "31" "2"  "3"  "8" 

Hope this helps,  Dirk
#
Dirk Eddelbuettel <edd at debian.org> writes:
Or, more longwinded, but with less assumptions about what goes before
the dot:
[1] "11" "11" "11" "31" "2"  "3"  "8"

or,
[1] "11" "11" "11" "31" "2"  "3"  "8"
#
On 18 Aug 2005 at 21:17, Peter Dalgaard wrote:

            
Wow, thanks a lot for all the valuable suggestions.

Bernd