- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove all text from a string before a particular character in R?
Sometimes we want to extract a sub-string from a big string and that sub-string lies after a particular character. For example, a string could be “Learning.Computer.Science.is.not.difficult-Author” and we want to extract the word Author from it. This can be done with the help of gsub function.
Examples
x1<-"Learning.Computer.Science.is.not.difficult-Author" gsub(".*-","",x1) [1] "Author" x2<-"Learning.Computer.Science.is.not.difficult Author" gsub(".* ","",x2) [1] "Author" x3<-"Learning.Computer.Science.is.not.difficult&Author" gsub(".*&","",x2) [1] "Learning.Computer.Science.is.not.difficult Author" x3<-"Learning.Computer.Science.is.not.difficult^Author" x3<-"Learning.Computer.Science.is.not.difficult&Author" gsub(".*&","",x3) [1] "Author" x4<-"Learning.Computer.Science.is.not.difficult%Author" gsub(".*%","",x4) [1] "Author" x5<-"Learning.Computer.Science.is.not.difficult#Author" gsub(".*#","",x5) [1] "Author" x6<-"Learning.Computer.Science.is.not.difficult@Author" gsub(".*@","",x6) [1] "Author" x7<-"Learning.Computer.Science.is.not.difficult~Author" gsub(".*~","",x7) [1] "Author" x8<-"Learning.Computer.Science.is.not.difficult/Author" gsub(".*/","",x8) [1] "Author" x9<-"Learning.Computer.Science.is.not.difficult;Author" gsub(".*;","",x9) [1] "Author" x10<-"Learning.Computer.Science.is.not.difficult:Author" gsub(".*:","",x10) [1] "Author" x11<-"Learning.Computer.Science.is.not.difficult< Author" gsub(".*< ","",x11) [1] "Author" x12<-"Corona Virus has changed the world -Nizam" gsub(".*-","",x12) [1] "Nizam" x13<-"Corona Virus has changed the world :Nizam" gsub(".*:","",x13) [1] "Nizam"
- Related Articles
- How to remove a particular character from a String.
- How to remove only last character from a string vector in R?
- How to remove a particular value from a vector in R?
- How to remove partial string after a special character in R?
- How to remove all common character from string array elements in android?
- How to find the count of a particular character in a string vector in R?
- How to remove the last character from a string in Java?
- How to extract string before slash from a vector in R?
- How to remove the first and last character in a string in R?
- How to remove all instances of a specific character from a column in MySQL?
- C# program to remove n-th character from a string
- Remove all except the first character of a string in MySQL?
- How to remove all non-alphanumeric characters from a string in MySQL?
- Java Program to Remove All Whitespaces from a String
- How to remove all whitespace from String in Java?

Advertisements