Last active
April 7, 2018 08:56
-
-
Save niebert/8bc998abde0f8d733e98794a6938c714 to your computer and use it in GitHub Desktop.
Example Application of Regular Expression in BBEdit / TextWrangler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
——————— Group Pattern and Use Found Patterns ——————————————————————————————————————————————————————— | |
see https://gist.github.com/ccstone/5385334 for further details on definition of regular expression | |
(1) Search Example: | |
enwiki: 'https://en.wikipedia.org', | |
dewiki: 'https://de.wikipedia.org', | |
roa_rupwiki: 'https://roa-rup.wikipedia.org', | |
(2) Replace Example: | |
enwiki: 'https://en.wikipedia.org', | |
enwikipedia: 'https://en.wikipedia.org', | |
dewiki: 'https://de.wikipedia.org', | |
dewikipedia: 'https://de.wikipedia.org', | |
roa_rupwiki: 'https://roa-rup.wikipedia.org', | |
roa_rupwikipedia: 'https://roa-rup.wikipedia.org', | |
(3) Search - Regular Expression: | |
([a-z_]+)wiki: 'https://([a-z\-]+).wikipedia.org', | |
(4) Replace - Regular Expression: | |
\1wiki: 'https://\2.wikipedia.org',\n \1wikipedia: 'https://\2.wikipedia.org', | |
(5) Comments for Regular Expression: | |
\n newline | |
\1 first matched group (e.g. "en" or "de" or "roa_rup" as part of the wiki ID | |
\2 first matched group (e.g. "en" or "de" or "roa-rup" as part of the URL | |
( ) Brackets group the pattern for reuse in the replace definition | |
escape brackets with \( or \) if you have brackets in your pattern |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The regular expressions in BBEdit or TextWrangler are defined in Perl like way, see https://gist.github.com/ccstone/5385334 for further details on definition of regular expressions.