I have a JSON file, and it has double quotes around keys and values. I want to remove double quotes from the keys(I know it would be invalid JSON, but still trying something). to do so I used this regex
:%s/"\(\w*\)":/\1:
But now the issue is that some of the keys have hyphen(maybe multiple) in them. The aforementioned solution won't work anymore. It only selects the keys that don't have hyphens. I tried to find a solution for this, but couldn't find anything concrete. Would be very helpful if you could help a little.
Related
I had been trying to match multiline string and character literals in VS Code, but there is no support for highlighting across more than one line using a regex. This is a known issue. At the bottom of the issue, it is told to use a semantic highlight provider.
VS Code's Semantic highlight guide gives a set number of tokens to semantically highlight. My main problem is that multiline strings are not detected as tokens in the first place, so they cannot be modified to change to the right color.
I am trying to match a BQN string: A BQN string is a double quote, followed by any number of non-quote characters including newlines, followed by another double quote. Double quotes inside a string are escaped by typing two quotes: "qu""ote" translates to qu"ote.
I'd like to know if there is a way to syntax highlight multiline strings via this method or any other method available to a VS Code extension. Help and examples are highly appreciated.
I have data in sublime arranged as follows;
353154 0.001039699782
506472 0.02085443362
482346 0.08343533852
439791 0.001349253676
486087 0.9999999476
I am trying to put quotes and commas so as to get following output;
('353154', '0.001039699782'),
('506472', '0.02085443362'),
('482346', '0.08343533852'),
('439791', '0.001349253676'),
('486087', '0.9999999476')
I am aware of using CMD+Shift+L in order to move cursors right and left. But I need help on how to get the commas and quotes between the two columns. Kindly advise.
You can do this with regex search and replace. Select Find → Replace… and make sure the Regular Expression button (usually looking like this *) is selected. In the Find: field, enter
([\d\.]+)\s+([\d\.]+)
and in the Replace: field, enter
('\1', '\2'),
Hit Replace All and it will look like this
See the demo at regex101.com, which also explains what each of the capture and replacement groups do.
Please keep in mind that you'll have to delete the final comma , if that's not proper syntax for your language of choice.
I'm trying to do a find and replace in notepad++ where i remove the dashes from a set of numbers and letters formatted as following: aa-aaa-nn-nnnnn
I've considered writing a plugin, but it just seems like too much work to be worth it.
Here's an example of what I have and what I need.
I have this: <ISRC>AB-CED-12-34567</ISRC>
And the result should be: <ISRC>ABCED1234567</ISRC>
I've tried finding (A-Z+)-(A-Z+)-(\d+)-(\d+) and replacing this with \1\2\3\4
but then it can't find the "text". If I knew how to write the darned search codes, I could do this myself, but I just can't find a complete guide anywhere.
You're close, you want to use character class:
Ctrl+H
Find what: ([A-Z]+)-([A-Z]+)-(\d+)-(\d+)
Replace with: $1$2$3$4
Replace all
[A-]+ means one or more uppercase letter, if you want to match also lowercase, use [A-Za-z]+
Was hoping someone could help me with an issue I am having with escape characters in Cucumber/Watir.
I have automated tests setup. When I perform a search, 1 of the assertions I use to verify that the search has returned the correct result is to check the page for text. So my code looks like this:
Then /^I should see the following text: "([^"]*)"$/ do |str|
assert #browser.text.include?(str)
end
Here I pass in the text to search for in the string variable. e.g nike, reebok etc
So in my feature file the step is like this:
Then I should see the following text "search results for nike"
This works fine apart from 1 issue. 1 of the sites I am testing has decided to put the search term in double quotes i.e - search results for "nike"
As a result this screws up my test as I need to include the quotes as part of the search term. Therefore I need to put the word nike in escape quotes or else cucumber will recognise the first quotation around the word nike as a closing quotation. (as there is already a double quotes before it)
I have tried various different escape characters but nothing seems to work. For example I have tried the following:
\" – double quote
\\ – single backslash
Has anyone experienced similar problems and if so, how did you overcome the problem?
Thanks!
You need to change the regex rather than the string.
Problem: Your current regex says "([^"]*)", which says to match all characters between the quotations that are not quotations. This is not good given that you want to include quotations.
Solution: Change the step to the following:
Then /^I should see the following text: "(.*?)"$/ do |str|
assert #browser.text.include?(str)
end
The .* says to match all characters between the quotations. The ? makes the search lazy (instead of greedy). The ? is optional in this case, but would be important if there were additional parameters being captured. A good explanation of the greedy vs lazy can be seen at http://www.regular-expressions.info/repeat.html.
With the syntax highlighting in vim, I get the handy feature where the matching paren or bracket will be highlighted when I put the cursor over it. Is it possible to do the same thing for quotes?
While not eloquent, one workaround is to select everything inside of matching quotes. You can do this by using the command:
vi"
This will select everything in-between the quotes. However, you won't get proper results with nested quotes as it will match the first found ".
The problem with quotes is that they are symmetrical. It would be very hard to determine which quotes belong with each other.
For instance: "Which \"quotes\" go with each other in this statement?"
This has been discussed on the vim mailing lists a few times, as well as in the bug trackers of a few of the auto-delimiter type plugins. In every case that I've seen, it's been decided that this is better left as is.
The solution is here: Stackoverflow in matchquote except it has the unfortunate limitation that only the current line is considered.
matchit seems to comes close by allowing defining of multi-line matches of words such as if/endif but still no multi-line possibility that I can figure out to get matching for " and '.
VIM already highlights quoted text in a different color, so you can easily identify strings. Do you really need it to match quotes when the whole string is already highlighted?
From :h matchparen
The characters to be matched come from the 'matchpairs' option. You
can change the value to highlight different matches. Note that not
everything is possible. For example, you can't highlight single or
double quotes, because the start and end are equal.