Regex to select the end of template

CyberAP

Well-known member
I need to paste my code right where the template ends. I am at odds with regex so I am asking you to help me with this. Hope this will also help other people who want to include their code with TM.
 
I just need to insert my code right where the template's contents end. For example at the end of extra.css template.
 
Well I haven't played with the TM yet but if I assume correct, to literally add content to the end of a template regardless what is already in the template you would need to just capture all text and then replace that with all of that captured text + what ever you are adding.


If I am correct in thinking this will work...

in the expression
#.+#siu will literally capture everything

in the replace
$0 will put all that captured text back and then you can enter your data after that

example
$0

.content2 {
height:420px;
}

I need to play around with it still. Please let me know if that works for you
 
Nope, still no luck with this. Fun thing that even none of the regex works with filled templates. I tried @Mike's code and it doesn't work too.

Maybe there is a bug in beta 3.
 
It works for me...but the problem is that second expression will add it once if the template it blank and more if it is not.
 
Oh, sorry, that's my mistake. I was doing a string replace...
@Mike's code is working perfectly!

Thanks again for your help!
 
This works inserting at the end of a template if there is content...and also will insert into a blank template


#(.+|^\s*$)#siu

I think you should use that...*if you add content to the template later I think it will add your replacement multiple times with just ^\s*$ (oddly I was testing the same regex and didn't check the link until after I tested this)


*EDIT: I take that back , ^\s*$ alone will not add content if the extra.css is not blank which means if a person is using a style relying on this and adds content to the template the TM will not apply anymore
 
Last edited:
Top Bottom