I need to write a regular expression search which will locate when a line ends with the same text as the preceding line, but does not have the same first 10 characters. So in this example:
[11:12:21] Hello this is Tom. How are you?
[11:14:08] Hello this is Tom. How are you?
. . . I would need to search for consecutive lines for which the text was the same after the time entered in brackets.
I know that this search:
. . . will locate the first 11 characters and remove them.
. . . will locate lines where the first 10 characters are the same and remove them.
But I can't figure out how to structure the search so it checks the text from position 11 to the end of the line, and then checks if the text on the next line from the 11th character to the end of the line is the same.
You cannot do what you are asking with a regular expression.
(There is in fact a very wrong way to attempt this which is ridiculous and would lead to nothing but a maintenance nightmare.)
However in a programming language that uses regexes the algorithm that you would create would look like the following
1. Read a line
2. Parse the line to remove the timestamp.
3. Does it match the previous one? (Do whatever you want)
4. Otherwise save it for the next time
5. Go back to step 1 until there are no more lines to read.
My campaigns all follow the same naming convention, i am trying to use a Regex_Extract formula in DataStudio to create a new custom dimension that only displays the 4th last element in the below campaign: "ctatext"
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
Is this possible to use in MS Visual Studio using 'Edit->Find and Replace->Replace in files' and checking 'Use regular expressions' and if so, then what should be in boxes 'Find what' and 'Replace with:' ?
Lets say I want to "encrypt" the ID number 123456789 - add '*' to all the digits up to the last four - *****6789.
A starting point is to replace .*(....) with *$1. But it would produce *6789, which is too short.
How can I know how many chars the first .* matched?
It depends to a certain extent on what "non zero numbers" means, exactly. Does it mean 0only and exactly, or does it have to not match 0. 0.0 0.00 etc.
For the simple case of a just excluding a zero we can use the following perl regex:
I've anchored this on line start and end ^ ... $, but you might have other requirements. This will match e.g 1.2 -15 0.03 .12 15. and -0.3, and does not accept any of ., 0, 0., or 1.2.3. However it does accept 0.0, 0.00, etc, and I have not yet found a way to eliminate them from the pattern. There might be a way using lookahead/lookbehind matches Lookahead and Lookbehind Tutorial—Tips &Tricks, but so far I haven't been able to figure out how to tell the regex engine that the lookahead/behind should match the entire pattern. For example we can eliminate 0.0 by adding a negative lookbehind regex of (?<!0.0), but this also elminates 0.03, which is not what is wanted. Maybe someone else knows how to resolve this.
But maybe regex isn't the way to go. If you're working in Java or C# or C++ or ... , it's probably better to just read some input, check that the entire input parses as a number, convert to a number and then omit or complain if the value is zero - depending on what your use case is.
Keep Calm and Carry On
Last Visit: 31-Dec-99 19:00 Last Update: 1-Feb-23 2:40