-1

I am trying to remove non Arabic words in r and i tried this code but it is removed everything

> L<-"you المجدo to yes"
> gsub("[^\\p{InArabic}.,]+","",L)
[1] ""

closed as off-topic by karel, N0rbert, Eric Carvalho, Kevin Bowen, George Udosen Jan 2 at 6:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – karel, N0rbert, Eric Carvalho, Kevin Bowen, George Udosen
If this question can be reworded to fit the rules in the help center, please edit the question.

  • You likely need to add perl = TRUE in order for R to compile the regex in PCRE mode. Also I'm not sure that {InArabic} is supported - though {Arabic} does seem to be ex. gsub("[^\\p{Arabic}.,]+", "", L, perl = TRUE) – steeldriver Dec 30 '18 at 22:40
  • yes it worked thank you – Fatima Albusayyis Dec 31 '18 at 7:04
2

You need to add perl = TRUE in order for R to compile the regex in PCRE mode.

Also I'm not sure that {InArabic} is a supported character class - though {Arabic} does seem to be, at least in my version of R (R version 3.4.4 (2018-03-15) -- "Someone to Lean On"):

> L<-"you المجدo to yes"
> 
> gsub("[^\\p{Arabic}.,]+", "", L, perl = TRUE)
[1] "المجد"

Not the answer you're looking for? Browse other questions tagged or ask your own question.