Search code examples
regexsublimetext2find-replace

Sublime text regex find/replace not recognising regex


I have to find/replace A LOT of inputs in a lot of files that have name and are either required or have minlength/maxlength or ng-pattern attribute.

I made this regex:

<input([^\/\>]*?) name="([\S\_]+?)" ([^\/\>]*?)(required|pattern|minlength|maxlength)([^\/\>]*?)\/\>

I tested this regex on regex101.com (as a js regex though) and it works. Sublime probably has slightly different regex syntax than javascript, but I've been using regex find/replace a lot recently, and this is the first time it's not working.

I'm pretty sure it's these parts that are problematic:

([^\/\>]*?)

Any help would be appreciated.


Solution

  • < and > don't need to be escaped. So don't escape your the last character i.e change \> to >

    <input([^\/\>]*?) name="([\S\_]+?)" ([^\/\>]*?)
    (required|pattern|minlength|maxlength)([^\/\>]*?)\/>
                                                       ^ Don't escape
    

    instead of

    <input([^\/\>]*?) name="([\S\_]+?)" ([^\/\>]*?)
    (required|pattern|minlength|maxlength)([^\/\>]*?)\/\>
                                                       ^ Doesn't WORK in sublimetext