Skip to content

Instantly share code, notes, and snippets.

@niebert
Last active April 7, 2018 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niebert/8bc998abde0f8d733e98794a6938c714 to your computer and use it in GitHub Desktop.
Save niebert/8bc998abde0f8d733e98794a6938c714 to your computer and use it in GitHub Desktop.
Example Application of Regular Expression in BBEdit / TextWrangler
——————— 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
@niebert
Copy link
Author

niebert commented Apr 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment