0

supplose if I have a string such as

Input:

myString <- "myFunc(apple,mango,orange,banana)"

I want to make a regex such that I produce the following

Output:

myString <- "myFunc(input$apple,input$mango,input$orange,input$banana)"

How do I achieve this?

4
  • Maybe this will work instead: myString <- paste0("with(input, ", "myFunc(input1,input2,input3,input4)") If not what are the rule to govern insertion? Always after a ( or ,? Commented Jun 15, 2016 at 1:42
  • after a "(" for the first one and "," thereafter Commented Jun 15, 2016 at 1:47
  • 2
    how did you arrive at this problem, what are you really trying to do Commented Jun 15, 2016 at 2:59
  • @rawr excellent question! Commented Jun 15, 2016 at 12:59

1 Answer 1

2
myString <- "myFunc(apple,mango,orange,banana)"

gsub("(\\(|,)", "\\1input$", myString)

## "myFunc(input$apple,input$mango,input$orange,input$banana)"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.