Does anyone know a way (regex search or plugin or anything other mac tools) i could search for a string i want to replace but only if another string is not on the same line.
This is Html code and i would like to search all files in a project that contain string <button and change it to <button type="button" as long as it doesn't contain the string type on the same line?
Currently using either sublime and atom but couldn't figure out how.
This can be done with a regex search and replace in Sublime, using a negative lookahead. Select Find → Replace… and in the Find What: box enter
(<button)(?!.*?type)
and in the Replace With: box enter
<button type="button"
Make sure the Regular Expression button is selected on the far left at the top.
Here is a demo. Basically, the first group (delineated by parentheses ( )) finds the opening part of the tag - simple enough. The second group (?!.*?type) is a negative lookahead ?! that searches for any character . repeated zero or more times and giving back reluctantly *? followed by the word type. The first group will match only if the second group does not match.
Related
I have a text like this:
this is any text
Could sublime text convert it to?
this-is-any-text
insert hyphens between each space
In addition to the suggestions given in the comments, there is another option - the Case Conversion plugin. Edit → Convert Case contains Title Case, Upper Case, Lower Case, and Swap Case. Case Conversion provides:
snake_case
SCREAMING_SNAKE_CASE
camelCase
PascalCase
dot.case
dash-case
separate words
separate with forward slashes
separate with backslashes
To use it, simply highlight the section of text you want to convert and select the desired operation from the menu, or use the assigned keyboard shortcut, which will show up on the menu. You can combine this with Find by using a regex pattern to only select certain areas.
Note: While I have contributed to the Case Conversion repo (I added the backslash feature), I am not its author, just a very satisfied user.
I have done as indicated by #odatnurd in sublime text I have selected the first space, then the following with CTRL + D and finally when they have all been selected I put a hyphen - and they have all been converted to a hyphen
My question is very simple:
Is there a shortcut in Sublime Text 3 which allows to remove blank lines in a selected text? (same for blanks in a line)
For instance, how to make this text:
a
b
c
To become:
a
b
c
And this line:
I need to remove these blanks.
to become this line:
Ineedtoremovetheseblanks.
You don't need a plugin to do this, a simple regex search and replace will do. First, select the text where you'd like to delete the blank lines. Then, select Find → Replace… (or, hit CtrlH on Windows/Linux, ⌘⌥F on OS X). Make sure the "Regular Expression" and "In selection" buttons are selected:
In Find What:, enter ^\n, and make sure the Replace With: field is empty. Then, simply hit "Replace All" and this:
becomes this:
As a bit of explanation, the regular expression ^\n searches for the beginning of a line (^) immediately followed by a newline character (\n). If you suspect that some of your "blank" lines contain whitespace, like space or tab characters, you can use ^\s*\n instead - \s* matches 0 or more whitespace characters, including newline characters.
For your second example, use the same Find/Replace settings as above, except your regular expression should simply be \s*.
There is a package called Trimmer. You can install it via Package control.
After you got the package you can use its functionalities. Just highlight the text you want to change (or don't select anything if you want to change the entire file) and then choose:
1) Edit > Line > Delete Empty Lines
2) Edit > Line > Remove Blank Spaces
Alternatively, as Chris's answer already pointed out you can use the classic search & replace functionality that is already present in the editor.
AS my original answer was incorrect, I have found this package which will be suitable for your needs.
The package is called DeleteBlankLines, for Sublime Text 3, has the ability to delete blank lines for the entire document and within the selected text only, all from a key stroke just like you were after.
The package can be found here:
https://packagecontrol.io/packages/DeleteBlankLines
I prefer using \s+, which will get one or more (i.e., the + character) whitespace characters (i.e., the \s escape sequence).
The * character will do zero or more, which on some versions can break up the individual words into letters.
I have a text that it is in one row. My purpose is to bring every new statement to a new row. After every "." symbol I want next statement to be on new row. How to achieve that. I have already tried to replace .\s* with .\n but that delete rest of text and just replace it with a "."
Use the Notepad++'s Regular Expression search feature with ". matches newline" checked, Now type \.. in Find what and .\nText Text Text\n in Relace with and hit Replace all.
Updated
For every character including "-".
Find what: \.([^.]+),
Replace with: .\n$1
Use replace tool in Extended mode (not the regexp) and put "." to replace with "\n". Or escape the point which is a special character in regexp mode:
Is it possible to search for a specific text in cells and move it?
For example: "ABCD [45] - City"
Result: "[45] ABCD - City"
Of course you can.
It is possible by code, formulae or search/replace (using regex).
In your example you search for something in square brackets and put this finding in front.
A regular expression search here will be
search for: (.*)(\[.*\] )(.*)
replace by: $2$1$3
Don't forget to tick the option "regular expression"
[Everything to search and replace with this is explained in online help: F1]
If you want code or formulae to have the task accomplished: ask more specific!
In a Notepad++ or an editor with similar features, is there an easy to search for a word which contains a number? For instance, suppose numbers were denoted by "~", then if I searched for "abc~" in the following text:
abc4
abc not a number
I would simply get the first word.
Use the "regular expression" search mode. If you just want to find groups of numbers, use \d+. If you want it to select the whole word containing one or more digits, use \w*\d+\w*.
Type this regular expression in the Find dialog box (select the regex option):
\w*\d\w*