Eclipse - file search containing text - regex to include whitespace combinations? - regex

In Eclipse, if I search for charCode == 44in File Search>Containing Text, I miss out on all of the results that might have different spaces e.g. charCode== 44, charChode ==44 etc
Is there a way (I imagine with would require the Regular Expression option) to include the whitespace combinations in the search text?

You could use the regular expression
charCode\s*==\s*44
Explanation:
\s means any space character (space, tab, ...). The * means zero or more occurrences of the previous literal.
Note: Be sure to check the Regular expression checkbox to the right of the search field.

Related

In Textpad how to replace space in only part of a string

I have several html files (source code) which contain lots of text and include the code of many reports files linked to.
I need to replace every space ( ) in the filenames by the undescore sign (_). This replace must not affect the rest of the text.
The links all follow the same folder structure, but the filenames are all very different except their extension (.pdf)
For example, I have:
Please find the presentations:
href="/Portals/12/Documents/GE-Project/Amalty-WS/Joanna_POT Pb paint health econ env_RUS.pdf">Presentation 1
I need:
Please find the presentations:
href="/Portals/12/Documents/GE-Project/Amalty-WS/Joanna_POT_Pb_paint_health_econ_env_RUS.pdf">Presentation 1
In Windows, using TEXTPAD, I have tried find/replace using regex (/Amalty-WS/[a-z,A-Z,0-9,_, ,]*\.pdf) but can't figure out how to replace only the spaces.
You can use
(?:\G(?!^)|/Amalty-WS/)[^"\s]*\K\s(?=[^"]*")
Replace with _.
See the regex demo.
Details:
(?:\G(?!^)|/Amalty-WS/) - either the end of the previous successful match (\G(?!^)) or /Amalty-WS/ string
[^"\s]* - zero or more chars other than " and whitespace
\K - match reset operator that discards text matched so far
\s - a whitespace
(?=[^"]*") - followed with zero or more chars other than " and then a ".

How can I search for all strings not containing a '/' in vim?

I am trying to match lines in a file that contain only a single / so my thought is i can search for a string of any length that doesn't contain a / and then match exactly one / and then match another string of any length not containing a / and finally ending with a line break.
My attempt at this was [^/]*/[^/]*$. however this doesn't seem to work.
I went ahead and tried matching just parts of this pattern and started by just trying to match strings of any length not containing a / which I would think should be just [^/]* but this isn't working.
I am pretty familiar with regex but not as familiar with using it in vim so firstly, am I putting in my regex wrong for using vim? and secondly, if my input for vim is correct, then what is wrong with my regex?
You may search for all the lines matching your pattern using
:g/^[^\/]*\/[^\/]*$
Note that g will match all occurrences, backslashes need escaping here, and the pattern matches
^ - start of a line
[^\/]* - 0+ chars other than /
\/ - a /
[^\/]* - 0+ chars other than /
$ - end of a line.
Note that [^\/]* (negated bracket expression) won't match a line break sequence in Vim, unlike in text editors like Sublime Text 3 or Notepad++, thus, it will match exactly what you need.
Note that you may avoid escaping backslashes if you select another delimiter. See the Vim regex reference:
Frequently you need to do S&R in a text which contains UNIX file paths - text strings with slashes ("/") inside. Because S&R command uses slashes for pattern/replacement separation you have to escape every slash in your pattern, i.e. use "\/" for every "/" in your pattern... To avoid this so-called "backslashitis" you can use different separators in S&R.
So, you may also use :g~^[^/]*/[^/]*$~, or :g#^[^/]*/[^/]*$# as Amadan suggests.

Regular expression to find and replace wrong quotation marks

I have a document which has been copy/pasted from MS Word. All the quotations are copied as ''something'' which basically is creating a mess in my LaTeX document, hence they have to be ``something''.
Is it possible to make a regular expression that finds all these ''something'' where something can be anything (including symbols, numbers etc.), and a regular expression that replaces it with the correct quotation? I am using Sublime Text which is able to use RegEX directly in the editor.
The below regex would match all the double single quoted strings and capture all the characters except the first two single quotes(only in the matched string). Replacing the matched characters with double backticks plus the characters inside group index 1 will give you the desired result.
Regex:
''(.*?'')
Replacemnet string:
``$1
DEMO

Replace leading spaces with Notepad++

I'd like to use Notepad++ to replace all leading spaces on a line with a like number of given characters. So for instance, I want to change:
zero
one
two
three
into:
zero
#one
##two
###three
I haven't been successful at getting this working. I did find Regex to replace html whitespace and leading whitespace in notepad++, but wasn't able to get the result I wanted.
Is this possible with Notepad++? I'd rather not have to write code to do this...
As Tim's answer indicates, this can't be done in a single search/replace, however here is how you can accomplish the same task fairly quickly using multiple replacements:
Find: ^( *)[ ]
Replace with: \1#
Now just spam the "Replace All" button until it indicates that there were no matches to replace. This will replace a single space at the beginning of each line on each click, so it will require the same number of clicks as your most-indented line.
Make sure "Regular expression" is selected as the search mode.
You would need variable-length lookbehind assertions to do this in a single regex, and Notepad++ doesn't support these.
For the record, in EditPadPro you can search for (?<=^ *)\s and replace with #.

using findstr with regex to search through CSV

I was wondering if it's possible to use findstr to search through a CSV for anything matching this regular expression
^([BPXT][0-9]{6})|([a-zA-Z][a-zA-z][0-9][0-9](adm)?)$
I don't know which language you're talking about, but there is one obvious problem with your regex: The ^ and $ anchors require that it matches the entire string, and you seem to be planning on matching individual entries in your CSV file.
Therefore, you should use word boundary anchors instead if your regex engine supports them:
\b(?:([BPXT][0-9]{6})|([a-zA-Z]{2}[0-9]{2}(adm)?))\b
I've also added another non-capturing group around the alternation. In your regex the anchors at the start and end of the string would have been part of the alternation, which is probably not intended. Whether you really need all the other parentheses depends on what you're going to do with the match.
No, it is not possible to use findstr to search for matching substrings, especially those matching the complex expression you've provided.
findstr is a Windows built-in.
findstr /? shows the subset of regex that it can use:
Regular expression quick reference:
. Wildcard: any character
* Repeat: zero or more occurrences of previous character or class
^ Line position: beginning of line
$ Line position: end of line
[class] Character class: any one character in set
[^class] Inverse class: any one character not in set
[x-y] Range: any characters within the specified range
\x Escape: literal use of metacharacter x
\<xyz Word position: beginning of word
xyz\> Word position: end of word
This means that most of your expression is out the window.
Also, findstr can't limit its output to just the matched expression; it only identifies lines containing matches.
It is entirely unsuitable for the task described.