find and replace in notepad++ or vscode - replace

Sorry all guys, use the code to make it more clear and convenient. I have
pre-fec-ber-min { description "pm for terminal-device, includes minimum only"; }
post-fec-ber-min { description "pm for terminal-device, includes minimum only"; }
all { description "all of pm parameter type"; }
and I want to change it to
pre-fec-ber-min
post-fec-ber-min
all
The purpose is to remove all the brackets, so I can just copy it to define enum. Please tell me what I should write in find and replace in notepad++ or vscode?

An exact match might use the following find and replace:
Find: ^(\w+)\s+\{.*?\}
Replace: $1
This would capture the first word term at the start of the line, removing the bracketed expression which follows it.
Demo

In VSCode:
Select 1 open brace {
Select All Open braces Shift+Ctrl+L
Select till End of line: Shift+End
delete via Backspace Backspace
stop multi cursor: Esc

Related

how to select a line end with } using regex?

This is my input :
\frac{P}{H\textsuperscript{o\textsubscript2}}
I want to select a whole using regex. and get a text inside the grouping {...}.
In first bracket Should contains single character only. in next bracket multiple characters.
Only two brackets.
My regex:
\\frac\{(.)\}\{([^\}]{2,})\}
My regex select upto:
\frac{P}{H\textsuperscript{o\textsubscript2}
not selecting the last }. wt i do?
Could anyone help me?
Just add another } at the last in your regex.
\\frac\{(.)\}\{([^\}]{2,}})}
DEMO
OR
Check for balanced brackets like this,
\\frac\{(.)\}(\{((?:[^{}]|(?1))*)})
DEMO

Regex to replace function with an other

I am trying to create a regex statement to go through my code and replace a function with an alternative that takes different parameters.
The function I want to replace has this signature:
[Label( "some text", Tooltips.ToolTipName, typeof( someClass ) )]
I would like this to be replaced with.
[Tooltip( Tooltips.ToolTipName )]
Can someone assist in writing a regex statement that will detect the signature and extract the ToolTip variable so I can do this?
Thanks
Karl
You can use this regex:
.*Tooltips\.\w+.*
Working demo
I think this is the regex you'd use to find:
"\\[Label\\([^\\]]*(Tooltips\\.[a-zA-Z0-9_]+)[^\\]]*\\)\\]"
which says "literal bracket and paren followed by label and literal open paren, then possibly anything except the closing bracket, then tooltip, then anything but closing bracket, then close bracket.
Once you've found it, use group(0) to match the entire label, and group(1) to match the "Tooltips.name".
Then replace group(0) with "[Tooltip(" + group(1) + ")]".
You may be able to simplify or be more exact if you are certain of whitespace and that all attributes are single-line or not.

Regex to add part of string to end of line in my Text Editor

I'm using Sublime 2 Text Editor which accepts RegEx search and replace. I'm attempting to find a whole line, then replace that whole line with a string found in the line itself.
This is my text that I am searching:
strEventID = CheckForNull(reader("
strEventKey = CheckForNull(reader("
strEventTitle = CheckForNull(reader("
I want to this text to become:
strEventID = CheckForNull(reader("EventID"))
strEventKey = CheckForNull(reader("EventKey"))
strEventTitle = CheckForNull(reader("EventTitle"))
I know that FIND: (^.*$) will match the whole line and I can REPLACE with $1 and add to that line manually, but I can't figure out how to add part of the string back in.
Update:
(str(\w*).*)$
replace with $1$2")) or $1$2"\)\) here in notepad++.
Make sure the ". matches newline" is unchecked
old answer:
Try:
^(str(.*\b).*)$
replace with $1$2")).
I don't have sublimeText with me right now, but this test http://regex101.com/r/hM2oX2/1 says group 1 is the whole line, and group 2 is your first match. concatenate...
In Sublime, you can use the following regular expression: \K resets the starting point of the reported match and any previously consumed characters are no longer included.
Find What: str(\w+).*\K
Replace With: $1"))

Regexp different behaviours in notepad++

I have a set of words like this
"text1
"text2
"text3
which i need to convert to a quoted text which I was able to do with stackoverflow help like this
Find: ^\".*$
replace: $0"
There are another set of words like this
text1
text2
text3
which i need to convert to 1 quoted text which i was able to do
Find: ^(.+)$
Replace: "$0"
But in this case i was able to do it only by clicking replace all and not replace.
Can anyone tell why it's happening like this and How can I achieve this without using replace all and by using only replace?
Take care of the second replacement, it will replace "text1" by ""text1"".
Use this instead:
find what: ^[^"\n]+$
replace: "$0"
It should be working with Replace All and not Replace in any case. The function can also be affected by the position of the cursor and the direction to find/replace.
To be certain, you can place the cursor at the beginning of the file, ensure that the find direction is 'Down' and use Replace All.
Now to the regex, yes, you can do it in a single replace. Use this find:
^(?:")?(.*)$
And this replace:
"$1"
regex101 demo.
The (?:")? will consume the first double quote if present so that it isn't placed in the replace later on.
There's no way you used "Replace" only once in the first case! You must have pressed it 3 times (as many as your matches).
In both situations you need "Replace all", since you want multiple global matches. When pressing the "Replace all" button it's like using Perl's /g & /m modifiers in your substitution, you can experiment here to see what I mean.
BTW the use of a capture group (the parenthesis) is redundant in your 2nd example, use find: ^.+$ and replace: "$0".

Sublime text find and replace with special characters

I suck at regular expressions and what to do a simple find and replace of '}' to '} /n' notepad++ can recongise what I'm after as it has the 3 options of normal find and replace, special chars and full regex. I however only ever used to option two. How can I enable special characters in my search using sublime text 2.
Cheers
Joe,
In sublime you can use find & replace. Drag the replace panel large enough and use cmd + enter to go to a new line.
Hit replace all:
And thats it your sorted chap
If you want to replace } within notepad++ with } \n you can use the following rules:
find: }
Replace with: } \n
Searchmethod: Extended (\n, \e...)
Press replace all