1

I want to replace anything that has issue # 000... or issue #000... (note space between digits and pound sign) with an href url based on the digits part of that string. The ... represents any number of digits.

## Here is a MWE string:

News <- readLines(n=5)
CHANGES

* Fixed bug see GitHub issue #12

* Fixed bug see GitHub issue # 111. (John Doe)

News

## Here are the pieces of the href url

## Roots
roota <- "<a href=\"https://github.com/trinker/qdap/issues/"
rootb <- "\">"
rootc <- "</a>"

## Here's the desired output

c("CHANGES",                                       
    "",                                              
    "* Fixed bug see GitHub <a href=\"https://github.com/trinker/qdap/issues/12\">issue #12</a>" ,             
    "",                                              
    "* Fixed bug see GitHub <a href=\"https://github.com/trinker/qdap/issues/111\">issue #111</a>. (John Doe)"
)

## Here's my initial attempt at extracting the pieces

gsub("(.)(issue)(.[#])(\\s*)([0-9]+)", "\\1", News)

## Grabbing the digits I could almost paste them together with

paste(roota, DIGIT_GRABBED, rootb, "issue #, DIGIT_GRABBED, rootc)

*I marked this with a regex tag but note that R regex is a particular breed and you should be familiar with R if you answer.

1
  • @Josh yeah, fixed that. Commented Sep 5, 2013 at 19:17

1 Answer 1

1

You could simply use:

gsub(pattern="issue *# *([0-9]+)", replacement="<a href=\"https://github.com/trinker/qdap/issues/\\1\">issue #\\1</a>", x=News)
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect and easier than what I was trying. I'll check as soon as 10 mins is up.

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.