Is it possible to run a regex snippet in Sublime text. Either by using a keyboard bind, or by creating a package?
The expression is
^\s*$
And it removes all double RETURNs/Lines in a document. Very handy for the OCD in me.
Any help, hints, tips or suggestions on this are more than welcome.
Thank you
You can hit Ctrl+H, for 'replace', this brings up a box at the bottom of the screen, click the .* button, enter ^\s*$, and it'll find all double enters, and you can replace them with whatever.
or there is a plugin that looks pretty powerful that should also allow you to do this called RegReplace.
Related
I have a question that's been bugging me for quite some time now. I'd like to minimize my mouse usage while working in IntelliJ.
When doing searches (ctrl+f) or replacing text (ctrl+r) I always have to manually check the "Regex" checkbox when I want to use regex. Is there a quick way to toggle this checkbox with my keyboard, or do I always have to use my mouse for that?
Simply tabbing to the checkbox does not seem to be an option as using tab simply jumps between the search and replace input-boxes.
I can't seem to find anything in the keymap settings nor on google :(
Thanks in advance. :)
Just hold Alt/Option button to see the mnemonics underscore. In my case I should use Option x to enable Regex.
I'm trying to make a snippet that is triggered by a regular expression. Is it even possible in Sublime Text 3?
I've tried this but it doesn't trigger. I've already checked that sublime replaces it correctly with the Find and Replace option.
<snippet>
<content><![CDATA[$1_$2
]]></content>
<tabTrigger>([a-zA-z])(\d)</tabTrigger>
<description></description>
<scope>text.tex.latex</scope>
</snippet>
I want my snippet to be triggered by pressing tab after any word that matches a character followed by a digit and replace it with the character, a _, and the digit.
Examples
a1 turns into a_1
X0 turns into X_0
The trigger text for a sublime-snippet file has to be literal text in order to trigger; Sublime won't match it based on a regular expression. To do something like that you need a plugin command that is bound to the tab key (for example) that triggers a command that examines the text to the left of the cursor to see if it matches the regex and then expand it based on that.
I'm not aware of a general purpose package that does something like this (although Emmet does this for expanding HTML tags, it's not generic and is known to interfere with regular tab completion) but there may be one listed on package control.
This forum post on the Sublime forum includes a sample plugin that does something very similar to this that may be useful as a starting point for something like this, though. Based on your examples above, it should do what you want as long as you swap the scope in the example for the one from your snippet so that it triggeres in LaTeX files instead of Markdown. You may want to rename the command as well in that case.
[Edit] If you're not sure how to use plugin in Sublime Text, this video covers how to do it.
My guess is that, maybe this expression,
(?i)(?<=<tabTrigger>[a-z])(?=\d<\/tabTrigger>)
replaced with _ might be something that you might have in mind, for instance.
If you wish to explore/simplify/modify the expression, it's been
explained on the top right panel of
regex101.com. If you'd like, you
can also watch in this
link, how it would match
against some sample inputs.
I am using NetBeans 8.2. I am working in the code editor window and trying to use regex in combination with the NetBeans find/replace feature. I have the regex button turned on.
I am trying this
on this code
specStripWidthUpper: $("#uniflytebundle_quoteitem_QuoteRing_specStripWidthUpper"),
specStripWidthLower: $("#uniflytebundle_quoteitem_QuoteRing_specStripWidthLower"),
The result I would like would take 1st Category found in find regex
specStripWidthUpper
and repeat it on other side of colon ":" like
specStripWidthUpper:specStripWidthUpper
instead it replaces the selection with $1. looking like
specStripWidthUpper:$1,
specStripWidthLower:$1,
Is there a NetBeans setting to run regex for the replace input window or am I doing something incorrect?
Thank you in advance for your time and effort.
Netbeans (8.2?) does not like the lookarounds. I do not know if this is a new thing but you can get around it with a simplified pattern.
However, your pattern does not capture the part you want to repeat, i.e. specStripWidthUpper (you can see this when you toggle the Select option).
Try it like this:
(\w+)(?:\:)(.*),
$1:$1
You might be required to anchor the query to avoid false positives.
I have a problem about find and replace in notepad++
I want to find a space+space in text and replace with just one space. But my area i want to find and replace is between start function and close function (ex: <div>...</div>). My file is .xml so it have alot of function.
So please help me. Thanks for your great help :)
Highlight the selected area, Ctrl+F for Find, hit the Replace tab, make sure the In Selection box beside Replace All is ticked.
Problem:
^.+ matches only the first line of the source code in dreamweaver. I need it to match each line so that I can wrap each full line in P tags. I have 500 files to do this in.
I know ^ should match the beginning of a line and I also know that multi-line mode must be enabled for it to work on each line and not just at the beginning of the file. I also know dreamweaver uses javascript source code.
Is lack of multi-line mode the problem? Is there any way to turn it on in dreamweaver? I tried using /m at the beginning search to enable multi-line mode, but that didn't work either.
I'm open to any solution for my current problem, even if it involves a different program. However, a fix for dreamweaver is ideal, 2nd place is a way to do this in notepad++, 3rd place is a way do to this in python or something (I only know javascript, you'll have to spell it out exactly in another language).
Thank you,
robert
p.s.
I found I can "select all > right click > selection > indent" to add two spaces to the beginning of each line in dreamweaver. This allows me to find the beginning of each line with / {2,}/. I really don't want to select all > indent on all 500 files, but i'm about to start since I've already spent a few hours bludgeoning dreamweaver.
Don't use Dreamweaver for this - use Notepad++ (since you are familiar with it) at its regular expression support is superior.
If you are comfortable with a more robust scripting language (Python, Ruby, Perl, etc.) then that would be an ever better way to do it.
The way that I might do this in DW would not involve using the find-replace tool's "Regular Expression" option, but instead using just plain old matching on a CrLf.
In the Find portion, since you can't directly enter a CrLf, you'll have to copy one to your clipboard beforehand and paste it in where needed.
In the Replace portion, replace with:
</p>[CrLf]
<p>
Again, be sure to paste in a proper "[CrLf]". This will work on all but the very first and very last lines of your document, so I know this isn't a 100% solution. There are probably better solutions using other tools that someone else can recommend!
Good luck!
-Mike
I had a flash of insight right after posting. (isn't that the way of it?)
Dreamweaver can find the end of each line with \r\n so instead of trying to work forward, i should have just worked backwards.
search: (.+)(\r\n)
replace: <p>$1</p>$2
[\w\W]* matches anything, including a newline. Its greedy, so it fact it matches everything.