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?
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
You need the regex #(\d+) and replace with [#$1](https://github.com/repo/issues/$1)
Try this regex for what you are trying to do
#[0-9]{1,3}
Related
I read from somewhere that Datastudio use little bit different Regular Expression from other places: that it uses RE2. I, however, manage to find a site to test for RE2 regex and able to get it running, but it was not working on Data studio.
I have this URL I wanted to extract:
/marketing/news-717777
/finance/news-123456?asdasdasd_asdad
I wanted the regex to extract the word with dash and number. "news-******".
The result would be like this
news-717777
news-123456
I cannot seem to get it to work on data studio. The code that I have tried are the following:
(news-).*(?=\?)|(news-).*
(news-).*(?=\\?)|(news-).*
(news-.*?)\?
(news-.*).*(?=\?)
The closest I get is to get news with number"news-***", but I cannot remove the "?" that comes after. Anyone has any ideas on this? Thank you in advance.
You can use several solutions here.
Solution 1: matching digits after a specific string (here, news-)
(news-[0-9]+)
See the regex demo, [0-9]+ matches one or more digits.
Solution 2: If there can be any char other than ? after news-, if there can be chars other than digits, you can use
(news-[^?]+)
See this regex demo, where [^?]+ matches one or more chars other than a ? char.
This is what I got:
.*([1-30000]#.*#).*
However, I would like to follow these rules without limiting to only 1 line.
For example, using: .*([1-30000]#.*#).* I could find:
5173#bunch of text here#
And what I would like to find:
5173#bunch of text here
of, bunch here, text
text here, bunch of
#
Hope I managed to be clear about my problem, thanks for the help.
Edit:
\b(?:[12]?\d{1,4}|30{4})#[^#]+#
Seems to be working, now the "challenge" is another, i want to save the number before the # (5173#) and replace what i got into another file where the same number is found.
You may use this regex:
(?<=\d#)[^#]+
Enable . matches newline and regex in your NP++ search box.
This matches text preceded by only a single digit followed by a pound and succeeded by a pound since NP++ doesn't support variable-length lookbehinds.
With the contribution of all, that is, joining what was answered by you. I got:
\b(?:[12]?\d{1,4}|30{4})#[^#]+#
I'm not sure if there's any mistake, I'm not familiar with all of this. :)
https://regex101.com/r/t7xBXk/1
I have two 1-6 digit numbers separated by a slash. I want these split up into groups of at most 3 digits, taking from the right.
For example:
0/1 -> [,0,,1]
1234/3 -> [1,234,,3]
12345/1234 -> [12,345,1,234]
123456/789123 -> [123,456,789,123]
I need to use a regular expression to do this because I want to do this for a location in NGINX. It's possible to do this with application logic but that is not the question due to performance.
Similar question which solves part of this was here using a negative lookahead: Regular expression to match last number in a string
What regex can achieve this split?
UPDATE:
This regex comes close to what I want (https://regex101.com/r/bQtNdK/3):
(?<prefix1>\d{0,3}?)(?<threes1>\d{0,3})\/(?<prefix2>\d{0,3}?)(?=\d)(?<threes2>\d{0,3})
It fails matching if the second number behind the slash is more than 3 digits long.
UPDATE2:
Now this regex works for most combinations (https://regex101.com/r/bQtNdK/5):
(?<prefix1>\d{0,3}?)(?<threes1>\d{1,3})\/(?<prefix2>\d{0,3})(?<threes2>\d{3})
I don't understand why this starts to fail if I use the same regex for prefix2/threes2 like prefix1/threes1 (i.e. make prefix2 also lazy). Any ideas how to solve this? So close...
I don't know that it's possible without the ability for the regex engine to remember all intermediate matches of a match group that matched an arbitrary number of times (.NET can do this, not sure what others). PCRE will apparently only remember the 'last' match for each group, other wise you could use something like this : (?<prefix1>\d{0,2})(?:(?<threes1>\d{3})*)\/(?<prefix2>\d{0,2})(?<threes2>\d{3})*\s
This regex seems to be correct now (regex101):
(?<prefix1>\d{0,3}?)(?<suffix1>\d{1,3})\/(?<prefix2>\d{0,3}?)(?<suffix2>\d{1,3})\/
Basically all over the document I have values like
2014-01-23 15:09:31.879958
I want to remove the last 6 digits and the . using find and replace. I've gotten
(\d{6})
To find the 6 digits but I also need it to find the . so I can replace it with nothing
Try: \.\d{6} - the \. escapes the dot.
In this case, you should be able to simply add a period to your find/replace.
As a test, I copied your example multiple times in a document. I then attempted to Find the following: \.(\d{6}) and replace with a blank
Give that a try and see if that works for you.
Cheers,
Edited to add the slash that I apparently didn't type. Silly.
I'm trying to write a regex that would detect if any combination of 4 non-whitespace characters existed between two strings. They will always be seperated by a comma. An example:
Labrador, Matador ---> this would match 'ador'.
Mississippi, Missing ---> This would match 'Miss' and 'issi'
Corporate, Corporation ---> This would match 'Corp' , 'orpo' , 'rpor' , 'pora' and 'orat'
It's been pretty hard to find something similar to this, and the closest I've found has said this is not possible in regex. It's definitely tricky, but I wanted to make sure that it was in fact not possible before looking for a different solution.
If it is impossible, would someone explain why?
For overlapping matches it is possible with a lookahead:
/(?=(\S{4}).*,.*\1)/
Note that there is one more issi possible in your second line example.
Test: https://regex101.com/r/rV3gN9/2
You can use this lookahead based regex:
(?=([a-zA-Z]{4})[a-zA-Z]*, *[a-zA-Z]*\1)
RegEx Demo
Though it will find issi twice since Mississippi has 2 instanced of issi.
This can be achieved with backreferences:
\w*([a-zA-z]{4})\w*, \w*\1\w*
See example: https://regex101.com/r/eW8hB7/1