sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
804 stars 39 forks source link

Boost Extended Format String Replacement Syntax #1524

Open keith-hall opened 7 years ago

keith-hall commented 7 years ago

Summary

In Sublime Text, the Find and Replace panels currently only allow Perl Format String Syntax replacements. However, the regex library that ST uses for find and replace supports an Extended Format String Syntax. This extended format is already implemented for snippets and symbol transformations.

I think it would be great if it could be used in the find and replace panels too, to allow conditional replacements.

Steps to reproduce

  1. Open a new tab, plain text syntax
  2. Type lorem Tab
  3. Open the Find and Replace panel
  4. Ensure regex mode is enabled
  5. Find What: \b(?:(\w{3})|(\w{4}))\b
  6. Replace With: (?1three)(?2${2}4:3)
  7. Replace All

Expected behavior

Allow conditional replacements in the find and replace panel.

Lorem ipsum dolor three3 amet4, consectetur adipisicing elit4, three3 do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim4 ad minim veniam,
quis4 nostrud exercitation ullamco laboris nisi4 ut aliquip ex ea commodo
consequat. Duis4 aute4 irure dolor in reprehenderit in voluptate velit esse4
cillum dolore eu fugiat nulla pariatur. Excepteur sint4 occaecat cupidatat three3
proident, sunt4 in culpa three3 officia deserunt mollit anim4 id three3 laborum.

Actual behavior

The replacement is treated literally.

Lorem ipsum dolor (?1three)(?2:3) (?1three)(?2:3), consectetur adipisicing (?1three)(?2:3), (?1three)(?2:3) do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut (?1three)(?2:3) ad minim veniam,
(?1three)(?2:3) nostrud exercitation ullamco laboris (?1three)(?2:3) ut aliquip ex ea commodo
consequat. (?1three)(?2:3) (?1three)(?2:3) irure dolor in reprehenderit in voluptate velit (?1three)(?2:3)
cillum dolore eu fugiat nulla pariatur. Excepteur (?1three)(?2:3) occaecat cupidatat (?1three)(?2:3)
proident, (?1three)(?2:3) in culpa (?1three)(?2:3) officia deserunt mollit (?1three)(?2:3) id (?1three)(?2:3) laborum.

Environment

keith-hall commented 6 months ago

For others coming across this, I have recently suggested a workaround utilizing snippets on the forum, which obviously isn't nearly as ergonomic as having Boost extended format string replacement syntax directly in the Find and Replace panel, but could help somebody...