I have a lot of java files:
Foo01.java
Foo02.java
Foo03.java
Foo04.java
Foo05.java
Foo01Bar.java
Foo01Bar.java
Foo02Bar.java
Foo03Bar.java
Foo04Bar.java
Foo05Bar.java
And I need to replace an expression in and only in FooXX.java classes.
Using CTRL + H in eclipse, in the file name pattern, I tried Foo(\d\d).java, but It does not work. If I write Foo*.java, every FooXXBar.java will also appears, and I don't want to.
What's the way to do it?
I don't think eclipse has the capability to do full regular expressions on file names. As far as I know you can use * to match any string and ? to match any single character for a file. As a result if your file list is similar to the above you can search for:
Foo??.java
For more complex file searches you probably need to use a combination of the unix/windows command line tools (depending on your OS choice).
Related
I have a large XML file, with many references to different file names, all PDF files. I want to replace all the different file names, with the a specific file name. I am using Notepad++.
For example:
cat.pdf
dog.pdf
bird.pdf
Replace all these with whale.pdf.
I have googled, searched, tried and failed for so long right now, and I cannot make it work. I don't know what I am doing wrong.
If you specifically intend to match several names you can do that in this way:
(cat|dog|bird)\.pdf\b
You can try
\w+\.pdf\b
Replace with whale.pdf.
I have one big file filled with custom text and scripts, that are used by one software, it crashes because of one problem
The software display whole text throught
{#HEXCOLOR}TEXT TEXT TEXT{/}
for example
{#FF00FF}Hello{/}
as we can see the whole text is inside custom script that starts from {#HEXCOLOR} and ends with {/} but in some lines the "{/}" is missing, that make program crash.
for example
{#FF00FF}Hello
It is possible some how to search for missing {/} in the file via Regular Expression ?
I tried by myself but failed:
{#[^{}]}.?{/[^{}]*}
you could use this pattern
({#[^}]+}[^{\r\n]+)(?={#|$)
and replace with \1{/}
Demo
This is probably real simple, but I can't seem to figure out how to do it.
I have an application in R (Shiny) where a user uploads to the application a *.zip file that contains all the components of an ESRI shapefile. I unpack these files into their own directory. This folder then, may or may not, contain a *.shp.xml file. At some point in my R code, I need to find the exact name of the *.shp file that has been unpacked, and distinguish it from the *.shp.xml file. How do I write the expression that will do that? I was thinking to use list.files, but I am unsure how to write the rest of the expression.
thanks!
With R regex patterns the "$" has special meaning as the end of a character element (and the 'dots' need to be escaped with \\, so
shpfils <- list.files(path, pattern="\\.shp$")
This should isolate your file -
Sys.glob("*shp")
as compared to
Sys.glob("*shp*")
which should give both the files
or
Sys.glob("*shp.xml")
which should give the .shp.xml file
Given the following file path:
/Users/Lawrence/MyProject/some/very/interesting/Code.scala
I would like to generate the following using a single regex replace (the root can be a constant):
some.very.interesting
This is for the purpose of generating a snippet for Sublime Text which can automatically insert the correct package/namespace header for my scala/java classes :)
Sublime Text uses the following syntax for their regex replace patterns (aka 'substitutions'):
{input/regex/replace/flags}
Hence why an iterative approach cannot be taken - it has to be done in one pass! Also, substitutions cannot be nested :(
If you know the maximum number of nested folders.You can specify that in your regex.
For 1 to 3 nested folders
Regex:/Users/Lawrence/MyProject/(\w+)/?(\w+)?/?(\w+)?/[^/]+$
Replace:$1.$2.$3
For 1 to 5 nested folders
Regex:/Users/Lawrence/MyProject/(\w+)/?(\w+)?/?(\w+)?/?(\w+)?/?(\w+)?/[^/]+$
Replace:$1.$2.$3.$4.$5
Given the constraints this is only thing you can do
Input
/Users/Lawrence/MyProject/some/very/interesting/Code.scala
Regex
^/Users/Lawrence/MyProject/[^/]+/[^/]+/[^/]+/Code.scala
or
^/[^/]+/[^/]+/[^/]+/([^/]+)/([^/]+)/([^/]+)/
Replace
\1.\2.\3
Update
This gets you closer, but not exactly it:
Regex
(^/Users/Lawrence/MyProject/|/Code\.scala$|/)
Replacement
.
Output would be:
.some.very.interesting.
Without multiple replacements in a single line and without recursive back references it's going to be hard.
You might have to do a second replacement, replacing something like this with an empty string (if you can):
(^\.|\.$)
In Eclipse, using the File Search feature, I am trying to do a file search over a large package for files containing <button and class="someclass", but without type="button".
In a more general sense, how do I search for some text while excluding results of they contain another bit of text?
CTRL + H and then choose File Search, there you can check the Regular expression option.
In order to get what you want, you can try entering something like this:
^(?!.*type="button").class="someclass".$
You can get more general regex information for Eclipse's File Search at this page.