regex registry replace - regex

I have bunch of windows registry .reg files and would like to make some changes into them, replacing SID with HKCU.
files look like this:
[-HKEY_USERS\S-1-5-21-**********-********-*********-500\SomeKey\SomeSubKey]
blah blah blah
[-HKEY_USERS\S-1-5-21-**********-********-*********-500_Classes\SomeKey\SomeSubKey]
[HKEY_USERS\S-1-5-21-**********-********-*********-500\SomeKey\SomeSubKey]
blah blah blah
[HKEY_USERS\S-1-5-21-**********-********-*********-500_Classes\SomeKey\SomeSubKey]
and the expected result would be like this:
[-HKEY_CURRENT_USER\SomeKey\SomeSubKey]
blah blah blah
[-HKEY_CURRENT_USER\Software\Classes\SomeKey\SomeSubKey]
[HKEY_CURRENT_USER\SomeKey\SomeSubKey]
blah blah blah
[HKEY_CURRENT_USER\Software\Classes\SomeKey\SomeSubKey]
I basically know what should be done but as regex is not my language maybe someone will help me :)
The idea is to search at the beginning of the line for [HKEY or [-HKEY
continue until *-500
replace HKEY* until *-500 with HKEY\.
Of course there is 500 vs 500_Classes and Software thing, but if given right direction I could figure out that myself or do a double run.
I would use Notepad++ for this.

Find
\[(-)?HKEY_USERS\\S-1-5-21-.{10}-.{8}-.{9}-500(_Classes)?(.*)
and replace with
[$1HKEY_CURRENT_USER(?{2}\\Software\\Classes)$3

Related

Is there any principle to use "--" (incremental slide) properly on xaringan?

Whenever I use -- to generate incremental slides. Sometimes it works but sometimes not.
For example, the following codes work different way. It seems -- works in very random way. I was wondering if there's suggested way to use this sign.
blah blah
--
blah blah
or
blah blah
--
blah blah
It's not random and the issue you are having is actually how markdown works and has nothing to do with --. So which one you should use depends on what you want to do. But mostly people want to show list items incrementally and in that case, you have to use the 2nd approach i.e. use space before and after --
Explanation
The first thing we need to understand is that -- simply put the contents written after this in the next slide. It's simple as that.
So if we write the text in markdown in such a way that it will continue to be on the same line, then using --, the texts will continue to be in the same line in the next slide, and if we write text in markdown in a way that text will be in a separate line, then using -- will have the same effect, but text written after -- will be in the next slide.
To make this clear with an example, say I have written text like this (notice no space between the lines)
blah blah
foo bar
They will be rendered in the same line (due to no space) like this,
blah blah foo bar
So if I use -- in this case between these two line like this,
blah blah
--
foo bar
So in the first slide, we will have
blah blah
and in the second slide
blah blahfoo bar
That is, in the next slide, the text continues to be on the same line. Also, note that there's no space between blah blah and foo bar. To create a gap,
we have to give one space before or after --. So as either,
blah blah
--
foo bar
or
blah blah
--
foo bar
In both cases, the text on 1st slide will be blah blah and 2nd slide blah blah foo bar. So in the case of incremental slides, a single space between two lines of text amounts to a space between the words in the same line.
Now in markdown, to create write text on a new line you have to use a space explicitly. So
blah blah
foo bar
will be rendered as two separate lines
blah blah
foo bar
So similarly, while creating incremental slides, you have to give at least two spaces in total between the texts. So,
blah blah
--
foo bar
or
blah blah
--
foo bar
or
blah blah
--
foo bar
all three approaches create on the 1st slide,
blah blah
and on the 2nd slide,
blah blah
foo bar
Hope I haven't created more confusion instead of making things clear.

Replacing regex match in pandas column with modified regex

I am trying to replace a regular expression match with modified regular expression.
Following is the column in my DataFrame.
df['newcolumn']
0 Ther was a quick brown appl_product_type in ("eds") where blah blan appl_Cust_type =("value","value")
1 Ther was a quick brown appl_product_type = ("EDS") where blah blan appl_Cust_type =("value","value")
2 Ther was a quick brown appl_product_type in ("eds") where blah b
3 Ther was a quick brown appl_product_type in = ("EDS") where blah blan appl_Cust_type = ("value")
4 Ther was a quick brown where blah blan appl_Cust_type
Name: newcolumn, dtype: object
i want to replace every occurrence of strings like "appl_product_type = ('EDS')' to 'upper(appl_product_type) = ('EDS')'
i am using following code but getting error
newcolumn.replace(value='upper\[\w]+\s+[in=]+[\s+\([\"\w+\,+\s+]+\)', regex='[\w]+\s+[in=]+[\s+\([\"\w+\,+\s+]+\)')
error: bad escape \w at position 7
is there a way to solve this ?? Please Help.
A couple of things -
you cant use \w in your replacement value and expect it to know what to fill in
your regex as is, is badly formatted. use r'' to make simpler regex strings
your question is unclear as you are asking one specific format while your regex is attempting to catch a lot more.
I have a slightly more clear solution to what you have attempted, but am unsure if this is exactly what you wanted given the ambiguity in you question. -
df['newcolumn'] = df['newcolumn'].replace({r'([\w_]+\s+(?:in|=|\s)+\(\"(?:\w+\"(?:\,)?(?:\s+)?)+\))' : r'upper(\1)'}, regex=True)

Vim: Delete all text surrounded by a start and an end

Say I've got this:
\item[1]\footnote{«footnote blah blah»}
footnote blah blah.
\item[2]\footnote{«blah blah footnote»}
random text
\item[3]\footnote{«this is not»}
more random text
I want to quickly delete \footnote{*} (that includes \footnote{«footnote blah blah»} \footnote{«blah blah footnote»} and \footnote{«this is not»}, but not \item[x] or the lines below that. How is this achieved?
Thanks!
I think the most accurate way would be to use:
:%s/\\footnote{.\{-}}//g
This will delete footnote and everything in between the braces. Using {.*} will delete everything up to the last brace even if it is outside of the footnote brace.
In escape mode
:1,$s/\\footnote{.*}//g

Replace contiguous line feeds or new line characters with a single newline in Flex

I need to replace multiple contiguous new line/line feed characters in flex with a single new line character.
Example:
The string
"My name is blah blah \n\n\n\n
My name is blah \r\n\r\n\r\n"
Should be converted to
"My name is blah blah \n
My name is blah \n"
Hope the example makes it easier to understand.
I am using a component to render it.
I guess using regex would be the easiest way to do this, but still it would be great if people can point me out to references/examples to get this done with ease.
I am using flex 4.5.
Thanks,
Neeraj
You can use String.replace method to do the job, it's possible to use both string or regular expressions to match some part of a string value. So regarding to your question the code will look like below:
var filter: String = "My name is blah\r\r\r blah \n\n\n\r\nMy name is blah\r\n\r\r\n\n\n\r\n";
filter = filter.replace(/(\r|\n)+/g, "\n");
multiple contiguous new line/line feed characters
If you mean sequence "\r\n" then:
var myString:String = "text\r\ntext\r\ntext\r\n";
myString = myString.split("\r").join("\n").split("\n\n").join("\n");

Using PIG with Hadoop, how do I regex match parts of text with an unknown number of groups?

I'm using Amazon's elastic map reduce.
I have log files that look something like this
random text foo="1" more random text foo="2"
more text notamatch="5" noise foo="1"
blah blah blah foo="1" blah blah foo="3" blah blah foo="4" ...
How can I write a pig expression to pick out all the numbers in the 'foo' expressions?
I prefer tuples that look something like this:
(1,2)
(1)
(1,3,4)
I've tried the following:
TUPLES = foreach LINES generate FLATTEN(EXTRACT(line,'foo="([0-9]+)"'));
But this yields only the first match in each line:
(1)
(1)
(1)
You could use STRSPLIT: http://pig.apache.org/docs/r0.8.0/piglatin_ref2.html#STRSPLIT
The regex to split on would be [^0-9]+ (i.e., not numbers)
This will effectively split on large portions of non-numbers, leaving only tokens of numerical digits.
Another option would be to write a Pig UDF.
REGEX_EXTRACT function may help you to get your desired output
REGEX_EXTRACT(input, 'foo=(.*)',2) AS input;