Need help trying to undo a VIM mistake [duplicate] - regex

This question already has answers here:
How do you make Vim unhighlight what you searched for? [duplicate]
(14 answers)
Closed 6 years ago.
So I'm practicing Ruby on Codeacademy and to save the work that I'm doing I copied and pasted my code onto my cmd prompt using VIM. However, I noticed that each line of code was commented with the '#' symbol and I wanted to remove them.
To be productive, I searched online how to use regex to search for all the hashtags and remove them with this command:
:%s/#//gc
Then this popped up:
replace with (y/n/a/q/l/^E/^Y)?
I pressed y every time until the message disappeared and now I'm stuck with all hashtags characters being replaced with a yellow rectangle. So instead of having this:
#
I have this:
[] but shaded in yellow for every time I use a hastag.
Any help would be much appreciated!

The yellow rectangle represents the characters that matched your expression. To clear the last search highlighting, use:
:noh
To uncomment the lines of code, I would just do this:
Use V to select each line, then
:norm x

Related

How can I extract file extension from string? [duplicate]

This question already has answers here:
How to use regex to get file extension?
(3 answers)
Closed 6 months ago.
We have a custom field defined in data studio which extracts and returns the file extension from a string in this case it is from the event label.
I have been using the below with some success
REGEXP_EXTRACT(Event Label, '\\.([\\w\\.-]+)$')
However I'm finding if the string contains multiple periods its including that aswell
Eg it's also extracting text like
07.21.pdf
7.22.PDF
07.21.docx
docx.pdf
How can I tweak my regex to only include from the last period and ignore any earlier.
You could try replacing [\\w\\.-] with [^\\.]
\\.([^\\.]+)$
[^\\.] will match everything except for ., so the match will not be able to contain dots inside.
The full formula would look like this:
REGEXP_EXTRACT(Event Label, '\\.([^\\.]+)$')

How to use awk to find a pattern, then move down a certain number of lines, and print? [duplicate]

This question already has answers here:
Printing with sed or awk a line following a matching pattern
(9 answers)
Extract Nth line after matching pattern
(3 answers)
Closed 2 years ago.
I am trying to use awk to find a pattern, then print the line X amount of lines below it.
For example:
This a line of something I dont need
More of what I dont need
This is what I want to print # <-- This contains the same information of what I want to print, but I do not want to print this line.
This is the pattern I need to find
This is unimportant
So is this
This too
As well as this
This is what I want to print # <-- This is the line I actually want to print
Notice how the same thing I want to print comes up multiple times, which is why I need to only print it when it comes after the pattern I define. So, theoretically, I would put the afformentioned text into awk and get:
This is what I want to print # <-- This is the line I actually want to print
That is occurrence of This is what I want to print after the pattern I defined.
I don't really know what I'm doing when comes to regex and awk, so I don't even know if this is possible. If it is not possible with these tools, then is there a way to do this at all?
PS:
I am using this in a script that gives information about one of my audio sinks. There are many sinks, that all have the same information fields. So, I am searching for the sink I want, then printing a certain field which comes after the name of the sink. I hope this makes sense.

take each line of a list and create one long single lined string wrapped by speechmarks [duplicate]

This question already has answers here:
How to edit all lines in Visual Studio Code
(9 answers)
Closed 3 years ago.
So essentially someone on our dev team made a bit of a big issue where they had changed all of the build actions on .csproj files and we are thinking of the easiest way to change them back.
We want to use regex to open all the csproj files via VSCode. The format to open multiple files in file explorer is
"filename" "filename1" "filename2"
my list is
com.Console.job1.csproj
com.Console.job2.csproj
com.Console.job3.csproj
com.Console.job4.csproj
my current regex
(.+)\n
then my regex to replace is
"$1"\s
which doesnt work at all
You can use this regex :
To locate pattern
([^\s]+)(\n)?
To replace :
"$1"
keep in mind the replace pattern contains a space at its end
Demo :
Here

Regex extract number from a string with a specific pattern in Alteryx [duplicate]

This question already has answers here:
Find numbers after specific text in a string with RegEx
(3 answers)
Closed 3 years ago.
I have string like this which looks like a url
mainpath/path2/abc/PI 6/j
From the string I need to get the number along with PI
Main problem is the position of PI part wont be always the same. Sometimes it could be at the end. Sometimes at the middle.
So how can I get that number extracted using regex?
I'm really stucked with this
It's as simple as using the RegEx Tool. A Regular Expression of /PI (\d+) and the Output Method of "Parse" should do the trick.
If you're using Alteryx... suppose your field name is [s] and you're looking for [f] (in your example the value of [f] is "PI")... then you could have a Formula tool that first finds /PI by first creating a new field [tmp] as:
SubString([s],FindString([s],"/"+[f])+1)
and then creating the field you're after [target]:
SubString([tmp],0,FindString([tmp],"/"))
From there run [target] through a "Text to Columns" tool to split on the space, which will give you "PI" and "6".

Increase print depth for lists in SML/NJ [duplicate]

This question already has an answer here:
Increasing the print depth in SML/NJ
(1 answer)
Closed 6 years ago.
I'm using Emacs to write a simple function in sml of about 4 lines and when I try to call the function/evaluate it in the buffer it returns this with 3 dots at the end
val it = [1,2,2,2,2,2,2,2,2,2,2,2,...] : int list
What's the dots at the end? My code doesn't print any dots. Is this is from Emacs or sml? any hints please.
Also I'm supposed to get a longer list like
[1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
is that why the dots there?
is that why the dots there?
Yes.