Last active
May 17, 2021 21:07
-
-
Save ruthtillman/264792a99a4a0e5bdf5a to your computer and use it in GitHub Desktop.
Regex to find/replace improperly-closed tags
This file contains hidden or 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
| # Regex to find/replace improperly-closed tags | |
| For situations with `<dc:title>Title<dc:title>` errors, etc. Syntax works with Sublime Text 2 directory-wide search. Example uses DC. NOTE: This search relies on line-breaks separating the tags you're looking at. Otherwise it can catch the second start tag, because "." includes everything except new lines. | |
| ## For Prefixed Tags | |
| Find: <dc:(.+)>(.+)<dc:(.+)> | |
| Replace With: <dc:\1>\2<\/dc:\3> | |
| ## For Non-Prefixed Tags | |
| Find: <(.+)>(.+)<([^/].+)> | |
| Replace with: <\1>\2<\/\3> | |
| ## If no attributes present | |
| Works for extremely simple XML. | |
| Find: <(.+)>(.+)<(\1)> | |
| Replace with: <\1>\2<\/\1> | |
| Disclaimers: No liability assumed, these should be taken as a starting point rather than an ending one. This scenario covers elements which contain text other basic information, not ones which contain child elements. Depending on tag contents, it may need to be slightly more complicated, test on known file before doing directory-wide search. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment