Using RegEx search and replace with Sublime Text 2, how can I replace my pattern matches (n) with n+1? And if there is no way to do this with search and replace, is there another easy way to do it?
My RegEx pattern is ^(\d{1,4})\n, and I'd like to be able to do $1+1, which currently just outputs the match with a literal "+1".
Regex is the wrong tool for that function. However, there is Sublime Text plugin just to do what you want: "Sublime Text plugin to increment/decrement all selected numbers"
Related
I am trying to do an advanced text search and replace in a text editor (I can use SublimeText or VSCode)
Input:
parameters['myParameter1']
parameters['myParameter2']
Expected output:
myParameter1
myParameter2
And I have hundreds of similar scenario in the file. So that's why I'm thinking of using regex to solve this.
Thanks
Hope this will help you out.
Regex demo
Regex search: parameters\['([^']+)'\]
1. parameters\[' this will match parameters[' Optinally if you have other keywords then parameters and which can be dynamic for that you can use [a-zA-Z]+ this will include all lower case and upper case.
2. ([^']+) this will match all except ', () will capture first match in $1.
3. '\] this will match ending ']
Replacement: $1
Note: If you are using gedit ubuntu you have to replace it with \1
VSCode can search all files in a directory, and it supports RegExp too!
Use ctrl+shift+f to search all files, hit the .* icon for RegExp.
A search expression such as parameters['(.*)'] replaced with $1 should work!
Check out the official guide for more info: VSCode Basic Editing
I'm looking for a way to lowercase selected BACKTICKED text using a regex in Notepad++
Here's an example string:
Select * FROM `Weird_TEXT` WHERE
And the desired output:
Select * FROM `weird_text` WHERE
I can find these strings (including the backticks) using the regex:
(?<=FROM )(.*)(?= WHERE)
`Weird_TEXT`
But I can't figure out how to replace the text as lowercase, I've tried using the following:
\1\L\2\L
\1\L\2\L\3
EDIT:
When I click Find Next in Notepad++, the backticks around the word Weird_TEXT are included in the selection. Could this be why the RegEx isn't working?
Just put this in the replace box:
\L$1
I am using the following regex to find strings of type
${a-z.a-z}
where the .a-z part is optional
Here's the regex I am using -
\$\{[A-Za-z]+\.*[A-Z][a-z]*\}
This will match strings like
${users}
${user.firstName}
I wanted the above matched strings to be replaced with the following corresponding replacements
<c:out value="${users}"/>
<c:out value="${user.firstName}"/>
How to do that in Eclipse?
Note, I can write a script to replace all such occurrences, but I do NOT want to replace all occurrences, but only certain ones by looking at them manually (therefore I want to do this through an editor).
I did this using groups -
Find : (\$\{([A-Za-z]+)\.*[A-Z][a-z]*\})
Replace With: <c:out value="$1"/>
In Notepad++, how do you Find and Insert (instead of Find and Replace) while using a regular expression as the search criteria?
For non regular expression, you can simply include what you are finding in the replace value, but for regular expression, that won't work. Ideas?
very simple, if you need to add some text to every match of your search you can use backreferences in regular expressions, so for example, you have:
this is a table.
and you want to get "this is a red table",
so you do search for:
(this is a)
and replace with (in regular expression mode):
\1 red
also note, that we've used parenthesis in our search. Each set of parens can be accessed in replace with the corresponding \N tag. So you can, for example search for
(this is).*(table)
and replace it with
\1 not a \2
to get "this is not a table"
Dmitry Avtonomov answered it right but I just wanted to add in case you have something dynamic in between two strings.
Example:
Line 1: Question 1
Line 2: Question 2
And you want to just add a dot after the end of each question number, you can add at this way.
In Notepad++
Replace : (QUESTION)(.*)(\r\n)
With : \1 \2. \3
Result:
Line 1: Question 1.
Line 2: Question 2.
Have you checked other posts?
Maybe this will help you get your answers:
Using regular expressions to do mass replace in Notepad++ and Vim
http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html
I have
2,5-3,5
3,5-4,5
...
and want
2.5-3.5
3.5-4.5
My "Find what" in Replace look like
[0-9],[0-9]
But I cannot make "Replace with"
\2.\1 to work. Nor does $2.$1.
This is clearly a simple task. What am I doing wrong?
Thanks
You need to specify groups to use replacement tags. I don't use notepad+, but if it's similar to other regex implementations \([0-9]\),\([0-9]\) should do the trick.
Did you checked Regular Expression checkbox(Search mode) in Notepad search and replace dialog?
I have just tried, this will work just fine for your case.
Search string: (\d),(\d)
Replace string: \1.\2
If you want to be more precise you can search and replace like this
Search string: (\d),(\d)-(\d),(\d)
Replace string: \1.\2-\3.\4
End just for reminder here is picture where you have to check regular expression option