r - Isolating specific numeric values in text -


i have significant amount of text trawl through on text csv file of various properties find square metre numeric value of properties is. example:

string <- "this wonderful 120 sqm flat stunning view" 

i know can use following extract numeric value:

sqm <- as.numeric(gsub("\\d", "", string))  

which returns numeric vector of '120', should. however, wondering if there more sophisticated way accomplish this, given there other irrelevant numeric values in text?

is there way search 'sqm' , return numbers precede it? many comments.

i believe regex lookahead should work:

library(stringr) ## string <- "this wonderful 120 sqm flat stunning view" re <- "((\\d+)(?=\\s?sqm))" ## r> str_extract(string, perl(re)) [1] "120" 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -