Github Regex Macro Sublime

You need to edit 2 files:

The JSON file with the Find and Replace pairs
The JSON file with the Macro command

JSON file with Find and Replace pairs

Go to the top menu Preferences/Package Settings/RegReplace/Rules-User

Follow this (http://facelessuser.github.io/RegReplace/usage/) syntax to see what type of string and values you can create.

Scraping Contributors

The page loads the content using JS so there is no way to scrape the content from the source code.

Copy Paste the contents of this page into Sublime and use Regex to create a CSV.

Edit Rules User

Inside the Rules User Sublime config file add these to the JSON

{
"format": "3.0",
"replacements": {
"github_get_contributor_url_remove_comma": {
"find": ",",
"replace": "",
"greedy": true
},
"github_get_contributor_url_join_lines": {
"find": "(^#.*)\\n(.*)",
"replace": "\\1,\\2",
"greedy": true
},
"github_get_contributor_url_remove_lines": {
"find": "^(?!.*#.*).+$\\n",
"replace": "",
"greedy": true
},
"github_get_contributor_url_remove_pound_sign": {
"find": "^#",
"replace": "",
"greedy": true
},
"github_get_contributor_url_remove_commits_word": {
"find": "commits /",
"replace": ",",
"greedy": true
},
"github_get_contributor_url_remove_plus_sign": {
"find": "\\+\\+ /",
"replace": ",",
"greedy": true
},
"github_get_contributor_url_remove_minus_sign": {
"find": "--",
"replace": "",
"greedy": true
},
"github_get_contributor_url_insert_github_url": {
"find": "^",
"replace": "https://github.com/",
"greedy": true
},
"github_get_contributor_url_remove_dotcom_number": {
"find": "(\\.com/)\\d{1,3}",
"replace": "\\1",
"greedy": true
},
"github_get_contributor_url_remove_spaces": {
"find": " ",
"replace": "",
"greedy": true
},
"github_get_contributor_url_add_first_row_header": {
"find": "^https://github.com/$",
"replace": "user_url,commits,lines_added,lines_removed",
"greedy": true
},
"github_get_contributor_url_remove_last_line": {
"find": "https://github.com/©.*",
"replace": "",
"greedy": true
}
}
}

Edit Commands User

Go to the top menu Preferences/Package Settings/RegReplace/Commands-User

Add this to JSON file

[
{
"caption": "Reg Replace: Github Get Contributor URL",
"command": "reg_replace",
"args": {"replacements": ["github_get_contributor_url_remove_comma", "github_get_contributor_url_join_lines", "github_get_contributor_url_remove_lines", "github_get_contributor_url_remove_pound_sign", "github_get_contributor_url_remove_commits_word", "github_get_contributor_url_remove_plus_sign", "github_get_contributor_url_remove_minus_sign", "github_get_contributor_url_insert_github_url", "github_get_contributor_url_remove_dotcom_number", "github_get_contributor_url_remove_spaces", "github_get_contributor_url_add_first_row_header", "github_get_contributor_url_remove_last_line"]}
}
]

Back to the page. Copy the whole page (Select All). Paste into Sublime.

Run Macro by doing Ctrl+Shift+P and type “Github Get Contributor URL”. Click on it and wait for the magic.

Leave a Reply