VOOZH about

URL: https://www.geeksforgeeks.org/r-language/replace-all-the-matches-of-a-pattern-from-a-string-in-r-programming-gsub-function/

⇱ Replace all the matches of a Pattern from a String in R Programming - gsub() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Replace all the matches of a Pattern from a String in R Programming - gsub() Function

Last Updated : 15 Jul, 2025
gsub() function in R Language is used to replace all the matches of a pattern from a string. If the pattern is not found the string will be returned as it is.
Syntax: gsub(pattern, replacement, string, ignore.case=TRUE/FALSE) Parameters: pattern: string to be matched replacement: string for replacement string: String or String vector ignore.case: Boolean value for case-sensitive replacement
Example 1: Output:
[1] "Goodsforgoods"
[1] "GeeksforBooks"
[1] "BooksforBooks"
Example 2: Output:
[1] "R Tutorial" "Java example" "Go-Lang Tutorial"
[1] "R Tutorial" "Java Tutorial" "Go-Lang Tutorial"
Comment
Article Tags:

Explore