Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I need to remove require.js from a bunch of files. The rest of the code needs to be preserved, and theres plently of nested functions, etc, which complicates things. I've pasted a sample below, basically I need 'use strict' to be the first line of code, and also strip the final }); from the code. Using sublime text 2. any regex or other ideas how to accomplish this?

EDIT: Need to remove everything before 'use strict' in example below, as well as closing }); Code in between, everything below 'use strict' except for the final closing }); needs to be left in tact. That code does contain functions and objects which complicate things. Example of what code may look like:

define([
    'backbone',
    'common',
    'marionette',
    'bootstrap'
],
function (Backbone, Common) {

    'use strict';

    var foo = 'stuff';

    foo = Backbone.Marionette.ItemView.extend({

        template: 'stuff',

        className: 'more stuff',

        events: {
            "click #a": "s"
        },

        s: function () {

            //
            // On click of a button, hide the modal
            //

            this.$el.modal('hide');
        }

    });

});
share|improve this question

1 Answer 1

up vote 0 down vote accepted

You can use this regex:

.*(?='use strict')|}\);$

Working demo

enter image description here

share|improve this answer
    
gives me an error that says 'found a closing repetition operator } with no corresponding { –  frajk Sep 3 '14 at 17:30
    
@user2934565 try to escape curly braces, use: .*(?='use strict')|\}\);$ –  Fede Sep 3 '14 at 17:31
    
that gets rid of the error, but if i have any other }); in the code (which I do), it identifies the first one it sees and traverses through matches from there. Is there any way to match the last one in the document specifically? –  frajk Sep 3 '14 at 17:35
    
@user2934565 that's because you aren't using the flags I specified in the regex. Noticed that in my screenshot (and also the link) I'm using the flags g global and s singleline. If you don't use both of them the regex won't work. –  Fede Sep 3 '14 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.