Notepad Regex Formatting
Lets say i have 100000 words in a list ( Example ) Apple Orange Grape Bannana .... etc
and i need them in this format
<command name="FindRep" enabled="True">
<find xml:space="preserve">FRUITS</find>
<replace></replace>
<flags></flags>
</command>
but changed FRUITS to Apples, Orange. Grape, etc etc
<command name="FindRep" enabled="True">
<find xml:space="preserve">Apple</find>
<replace></replace>
<flags></flags>
</command>
<command name="FindRep" enabled="True">
<find xml:space="preserve">Orange</find>
<replace></replace>
<flags></flags>
</command>
<command name="FindRep" enabled="True">
<find xml:space="preserve">Grape</find>
<replace></replace>
<flags></flags>
</command>
Solution 1:
- Ctrl+H
- Find what:
.+
- Replace with:
<command name="FindRep" enabled="True">\n <find xml:space="preserve">$0</find>\n <replace></replace>\n <flags></flags>\n</command>
- CHECK Wrap around
- CHECK Regular expression
-
UNCHECK
. matches newline
- Replace all
Explanation:
.+ # 1 or more any character but newline
\S+
Replacement:
<command name="FindRep" enabled="True"> # literally
\n # linefeed, you can use \r\n for Windows EOL
<find xml:space="preserve"> # literally
$0 # the whole match (i.e. the fruit name)
</find> # literally
\n # linefeed, you can use \r\n for Windows EOL
<replace></replace> # literally
\n # linefeed, you can use \r\n for Windows EOL
<flags></flags> # literally
\n # linefeed, you can use \r\n for Windows EOL
</command> # literally
Screenshot (before):
Screenshot (after):