Find and replace in Google Spreadsheet using Regular Expressions - regex

I would like to use the Google Spreadsheet Find and Replace function with the "Search using regular expressions" function activated to do a search and replace in my document.
Use case: Some of my cells contain erroneous linefeed characters at the end (leftovers from paste operation by some of the editors).
I'm using the following pattern to successfully find the cells
.*\012$
Is there some syntax for the "Replace with" field that lets me replace the cell's content by the string I found minus the \012 character at the end?
The Google Spreadsheet documentation does not contain any relevant information. https://support.google.com/docs/answer/62754?hl=en
Here's a screenshot of the box

You may use a capturing group (...) in the pattern around the part you want to keep, and use a $1 backreference in the replacement:
(.*)\012$
to replace with $1.
See the regex demo.

Related

Regular expression look-back matches correctly but doesn't replace in Notepad++ [duplicate]

I have the following CSS markup.
.previous-container{
float:left;
}
.primary-commands {
float:right;
}
Using the regex syntax search (?<=[\s,;])([a-zA-Z\-]+): it highlights the CSS property name as expected, however, upon clicking replace nothing is replaced. I have tried using group token syntax in replace line e.g. $[nth group] and any plain literal string replacement. No matter my attempts it will not replace the matched string with anything. I am using notepad++ version 6.7.5. Perhaps there is something obvious I am missing here?
Based on comments to the original question here are some work-arounds that solved my problem.
Option #1
Replace the lookbehind portion of the regex statement (?<=[\s,;]) with a simple non-lookbehind group matching statement such as ([\s,;]). This will continue to limit search results to strings beginning with the specified characters in the lookbehind. The only caveat is that in my replacement string e.g. $1 $2 I would need to leave out the undesired matched characters that should not be a part of the replacement string.
Option #2
Use the "Replace All" button. It will perform replacements correctly when using a positive lookbehind in your regex statement as opposed to using the "Replace" button for single replacement.
I went with Options #1 only because it achieves what I need while allowing me to still perform a single replacement at a time. With larger documents I don't want to use "Replace All" until I have thoroughly tested my regex expression.

Notepad++ Regex Find/Replace Using Look Behind not Working

I have the following CSS markup.
.previous-container{
float:left;
}
.primary-commands {
float:right;
}
Using the regex syntax search (?<=[\s,;])([a-zA-Z\-]+): it highlights the CSS property name as expected, however, upon clicking replace nothing is replaced. I have tried using group token syntax in replace line e.g. $[nth group] and any plain literal string replacement. No matter my attempts it will not replace the matched string with anything. I am using notepad++ version 6.7.5. Perhaps there is something obvious I am missing here?
Based on comments to the original question here are some work-arounds that solved my problem.
Option #1
Replace the lookbehind portion of the regex statement (?<=[\s,;]) with a simple non-lookbehind group matching statement such as ([\s,;]). This will continue to limit search results to strings beginning with the specified characters in the lookbehind. The only caveat is that in my replacement string e.g. $1 $2 I would need to leave out the undesired matched characters that should not be a part of the replacement string.
Option #2
Use the "Replace All" button. It will perform replacements correctly when using a positive lookbehind in your regex statement as opposed to using the "Replace" button for single replacement.
I went with Options #1 only because it achieves what I need while allowing me to still perform a single replacement at a time. With larger documents I don't want to use "Replace All" until I have thoroughly tested my regex expression.

Find and Replace with Regex in Microsoft Word 2013

I am editing an e-book document with a lot of unnecessary markup. I have a number of sections in the text with code similar to this:
<i>Some text here</i>
I am trying to run a regex find and replace that will find any phrase between the two i-tags, remove the i-tags, and apply a style to the text.
Here is what I'm using to search:
Find: (<i>)(*)(</i>)
Replace: \2
I'm also selecting Styles > i (for italic). This tells our conversion software to apply italics to the text. If I leave the i-tags, what ends up happening is ScribeNet's conversion process converts them to hex-values so that they show up as literal text in the e-book. Messy.
When I run this search, I get no results. I have "use wildcards" checked. What am I missing? According to Microsoft's help website, * is used to represent any number or type of characters, and individual strings are supposed to be enclosed in parentheses.
To search for a character that's defined as a wildcard, place a backslash (\) before that character. The * itself matches any string of characters, so use the range quantifier to match (1 or more times)
Find: \<i\>(*{1,})\</i\>
Replace: \1
Search for \<i\>(*{1,})\</i\> and replace with \1. Don't forget to check Use wildcard.
There is a reference table for Word's "regular expressions" here: http://office.microsoft.com/en-ca/word-help/find-and-replace-text-by-using-regular-expressions-advanced-HA102350661.aspx
< and > are special characters that need to be escaped
* means any character
{1,} means one or more times
There is a special tool for Microsoft Word called Multiple Find & Replace (see http://www.translatortools.net/products/transtoolsplus/word-multiplefindreplace) which allows to work around Word's wildcard limitations. This tool can use the standard regular expressions syntax to search and replace any text within a Word document. For example, to search for any HTML tags, you can just use <[^>]+> which will find opening, closing and standalone HTML tags. You can add any number of expressions to a list and then search the document for all of them, replace everything, see all matches for all the search expressions entered, replace only selected matches, and a few more things.
I created it for translators and editors, but it is great for any advanced search/replace operations in Word, and I am sure you will find it very useful.
Stanislav

Regex to insert text BEFORE a line containing a match?

I have a bunch of artists that are named in this fashion:
Killers, The
Treatment, The
Virginmarys, The
I need them to look like
The Killers
The Treatment
The Virginmarys
I'm able to match the lines with , The ((^|\n)(.*, The) is what I've used) but the more advanced syntax is eluding me. I can use regex on the replacement syntax as well (it's for a TextPipe filter so it might as well be for Notepad++ or any other Regex text editor).
You should be able to use the following:
Find: (\S+),\s\S*
Replace: The $1
Or include the The..
Find: (\S+),\s+(\S+)
Replace: $2 $1
Depending on your editor, you may be better off using \1, \2, and so on for capture groups.
Since you need to specifically capture the title before the comma, do so:
(^|\n)(.*), The
And replace it putting the "the" in the right place:
\1The \2
Regular expressions define matches but not substitutions.
How and in which way you can perform substitutions is highly dependant on the application.
Most editors that provide regular expression support work on a line per line basis.
Some of them will allow substitutions such as
s/^(.*Banana)/INSERTED LINE\n\1/
which would then insert the specific pattern before each match. Note that others may not allow newlines in the substitution pattern at all. In VIM, you can input newlines into the command prompt using Ctrl+K Return Return. YMMV.
In Java, you would just first print the insertion text, then print the matching line.

Regular expression to find a text as being a whole word

I am using the ABAP statement READ REPORT and I want to use FIND ALL OCCURRENCES OF REGEX. Let's say for example I want to search for SELECT but when I do FIND ALL OCCURRENCES OF REGEX 'SELECT', the return table gets lines that have SELECT-OPTIONS, SELECTION-SCREEN and SELECT.
How do I use regex to get only those lines with SELECT, discarding the other 2 possible matches in the example above?
Just go for `SELECT `
Note the extra space and the use of grave quotes (grave quotes so that the trailing space is considered). This simple solution is feasible because it's highly unlikely that there's a new line right after SELECT.
Your requirement is so simple that you don't need to use a regular expression.
http://sapignite.com/regex-in-abap/
OR
Download a PDF from this Link
http://www.google.co.in/url?sa=t&rct=j&q=how%20do%20i%20use%20regex%20in%20abap%20to%20search%20for%20a%20specific%20string%3F&source=web&cd=1&ved=0CCMQFjAA&url=http%3A%2F%2Fwww.sdn.sap.com%2Firj%2Fscn%2Findex%3Frid%3D%2Flibrary%2Fuuid%2F902ce392-dfce-2d10-4ba9-b4f777843182%26overridelayout%3Dtrue&ei=AsFxT9bJNdDqrQfdoe3hDQ&usg=AFQjCNHTHvQXYtYosCLPwj98Za-LMJbo7w&cad=rja
use
\bselect\b
\b stands for word boundary. It will not match aselect or selected
look at a good regex reference at mozila.org and try your regex at regexpal
There is a very cool playground for testing regular expressions: Run Report DEMO_REGEX_TOY with SE38 or SE80.