0

I need to go through a file and replace all instances where an issue is mentioned using the Github convention #xxx (where xxx is the issue number), with a link to the issue using the Markdown format.

So for example, this:

#143, #99

should be converted into this:

[#143](https://github.com/repo/issues/143), [#99](https://github.com/repo/issues/99)

I've gotten as far as to being able to select all the issues with three digits using:

#..[0-9]

but this leaves out the two or one digits issues (ie: #5 or #23)

Is there a way to generalize the above command to select all issues, no matter how many digits they have?

Once this is done, how can I make the replacement to add a link to each issue?

3 Answers 3

2

You should use this regex:

#[0-9]{1,3}

to match a issue # between 1 and 3 digits as [0-9]{1,3} will match a number that is 1 to 3 in length.

You can also use use word boundaries:

#[0-9]+\b
Sign up to request clarification or add additional context in comments.

3 Comments

well looks like you beat me :)
This works great for selecting the issues, thanks anubhava! Any idea how I could replace them with the correct markdown link?
You should match #([0-9]+)\b and replace it by: [$0](https://github.com/repo/issues/$1) Where $0 and $1 are back-references to the matched data.
1

You need the regex #(\d+) and replace with [#$1](https://github.com/repo/issues/$1)

3 Comments

The first regex isn't working for me Amit, it selects nothing.
The second one also isn't working, the number gets replaced by [#](https://github.com/repo/issues/). I'm using Sublime BTW, not sure if it's relevant.
@Gabriel try now. You don't need delimiters that I had used in Sublime
1

Try this regex for what you are trying to do

#[0-9]{1,3}

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.