Notepad++ How would I add a new line between two specific lines using the replace tool - replace

I am a novice modder and am trying to create a mod for a video game. There is a specific line I would like to add between every search instance. For example:
This is how its currently structured:
<property name="IsQuestGiver" value="false"/>
<effect_group name="Base Effects">
I would like to achieve this to all 200 instances in the file:
<property name="IsQuestGiver" value="false"/>
<property name="BodyHitPoints" value="9999"/>
<effect_group name="Base Effects">
Thank you in advance for your help!
I fiddled around with the replace tool but couldnt figure it out myself.

Search with regular expression search mode:
<property name="IsQuestGiver" value="false"/>
Replace text:
$0\n<property name="BodyHitPoints" value="9999"/>\n
Normally in regexp you need to escape some characters with \ like /, but not in notepad++.
The $0 is the match value, so rather than replacing the match text you can simply use $0.
\n is a new line character. If your using windows you might need to use \r\n instead.

Related

How to get the index by regular expression in ANT

I have a string with a version as .v_september (every month it will vary). In this i wanted to take the value after underscore, which means "sep" (First 3 letters alone).
By using the regex .v_(.*) i am able to take the complete month and not able to get the first 3 letters alone.
Can someone help me out how can I achieve this in Apache ANT.
Thanks !
Regex functions on properties are a bit awkward in native Ant (as opposed to working with text within files). Ant-contrib has the replaceregexp task, but I try to avoid ant-contrib whenever possible.
Instead, it can be accomplished with the loadfile task and a nested filter:
<property name="version" value=".v_september" />
<loadfile property="version.month.short">
<propertyresource name="version" />
<filterchain>
<tokenfilter>
<replaceregex pattern="\.v_(.{3}).*" replace="\1" />
</tokenfilter>
</filterchain>
</loadfile>
<echo message="${version.month.short}" />
Regarding the regex pattern, note how it needs to end with .*. This is because Ant doesn't have a "match" function that simply returns the content of a capture group. It's just running a replacement, so we need to replace everything in the string that isn't part of the group.
.* will capture everything and for limiting to capturing only three characters you need to write {3} instead of *. Also you should escape the . in the beginning of your regex to only match a literal dot. You can use this regex and capture from group1,
\.v_(.{3})
Demo

Checkstyle validation fail when needs multiple lines

I need to perform a validation rule on eclipse checkstyle, after a key { of method and before end key } should have a empty line, example:
public void wrongMethod() {
System.out.println("wrong method");
}
correct
public void correctMethod() {
System.out.println("correct method");
}
I try to use a RegexpMultiline in checkstyle rules xml file, doing some like this:
<module name="RegexpMultiline">
<property name="format" value=".+\{\n.+[;]"/>
<property name="message" value="should have empty line"/>
</module>
sure, this Regex expression can be better, the issue is, the multiline behavior works in a regex simulator site with the examples above, but in checkstyle dont. I search on a checkstyle documentation and not found a ready reature for this.
Anyone know a solution for this issue?
thanks.
Probably you run the check on files with CRLF line endings. If yes, then remember about \r in your pattern.
This works for me:
<module name="RegexpMultiline">
<property name="format" value="\{[\r]?\n(?![\r]?\n)"/>
<property name="message" value="should have empty line"/>
</module>
I've changed couple of things in the pattern:
.+ at the beginning is not needed
no need to match ;
negative lookahead is used

Using Wildcard/Regex for find & replace in Visual Studio

I need to replace different values of receiveTimeOut attribute with a receiveTimeOut="59:59:59"
Can wild card search be used to achieve this task, in Visual Studio?
<endpoint receiveTimeOut="10:10:20" someOtherProperty="x1" yetAnotherProperty="y1" />
<endpoint receiveTimeOut="10:50:20" someOtherProperty="x2" yetAnotherProperty="y2" />
...
<endpoint receiveTimeOut="30:50:20" someOtherProperty="x3" yetAnotherProperty="y3" />
I tried: using wildcard option in Find & Replace dialog, receiveTimeOut="*" but this selects complete line, receiveTimeOut="10:10:20" someOtherProperty="x1" yetAnotherProperty="y1" />
As you might have guessed, I am editing WCF service web.config and have to do this task manually & repeatedly.
Using the regex option...
Find: <endpoint receiveTimeOut="[^"]+"
Then...
Replace: <endpoint receiveTimeOut="59:59:59"
The [^"]+ part uses a negative character class that matches any character except for a double quote. The + will match it one or more times.
It turns out that this is actually quite simple to do with a regular expression.
Just use .* for your wildcard and check Use regular expressions.
For example, I have some grids and I want to find columns with an attribute of Visible="False" so a string might be:
telerik:GridBoundColumn name="name" Visible="False"
My search string would be: "GridBoundColumn.*Visible="False""
Done.
Ahmad's is the way to go. But as a naive and bit different alternative, one could search:
receiveTimeOut="[0-9]*\:[0-9]*\:[0-9]*"
This requires the data between the double quotes of the receiveTimeOut value has two colons (which are escaped) with any number of digits about them.

Regular Expression: Matching a string with a variable inside for Find/Replace - Notepad++

So, I'm trying to do a Find and Replace in notepad++ with regular expressions, because I have a 'Find' string that can have any number of characters between 2 quotes. Here is a sample of my data.
<myVar Variable="MY-VAR" Type="string"/>
<myOtherVar Variable="MYOTHERVAR" Type="int"/>
<finalVar Variable="FVAR" Type="string"/>
So, I want to match ' Variable="[everything inside the quotes]" T' and replace it with ' field="" t'.
I don't want to save what's in the quotes. The ultimate goal is to have lines that looks like this:
<myVar field="" type="string"/>
<myOtherVar field="" type="int"/>
<finalVar field="" type="string"/>
I think this has been my best attempt so far in the Find box, but ya'll can tell me if not. XD
/' variable="(\w+)" t'/
Thanks all!
Don't know the notepad++ regex syntax, but following idea should work:
try to replace
Variable="[^"]*"\s+T
with
field="" t
EDIT
I don't have windows machine, just installed notepad++ in a virtual box, and did a small test :)
the result looks like this:
With Notepad++ your RegEx will be:
Variable=".*"
Don't forget the last SPACE it's important. Replace it with
field=""
also containing a space as last character.
Greets

Regular expression to manipulate text file - Windows

I am having issues manipulating a text file to get my desired results.
For example, I have the following lines within a text file called sprocs.txt which was created from an svn diff, similar to this:
M https://localhost/svn/Repo/branches/projectA/sprocs/admin/foo.sql
M https://localhost/svn/Repo/branches/projectA/sprocs/foo2.sql
M https://localhost/svn/Repo/branches/projectA/sprocs/admin
M https://localhost/svn/Repo/branches/projectA/sprocs
I am trying to edit this file so that it keeps everything starting with /sprocs, but deletes each line that does not end in .sql. For example, the file above would return the following:
/sprocs/admin/foo.sql
/sprocs/foo2.sql
BTW: I plan to have these commands be handled by nant. Any ideas anyone? Thanks in advance.
This would do the job using pure NAnt:
<target name="go">
<property
name="file.path"
value="C:\foo\sprocs.txt" />
<foreach
item="Line"
in="${file.path}"
property="line">
<property
name="MATCH"
value="" />
<regex
pattern="(?'MATCH'/sprocs.*\.sql)$"
input="${line}"
failonerror="false" />
<if test="${string::get-length(MATCH) > 0}">
<echo message="match: ${MATCH}" />
<!-- do whatever you want to do with your match -->
</if>
</foreach>
</target>
Not as elegant as palako's solution but it also works.
$ cat sprocs.txt | sed -n 's/.*\(\/sprocs\/.*\.sql$\)/\1/p'
/sprocs/admin/foo.sql
/sprocs/foo2.sql
The following regex pattern should work for you, it will create a capturing group that will find anything starting with /sprocs and ending with .sql
(/sprocs.*\.sql$)
Be sure to enable the multi-line mode by passing it in the options for the nant regex otherwise this will not match properly. I believe this is the m option as is explained here