Remove new lines in quotations from csv with Regex

Regex Expression to remove new lines which are quoted in csv.

Csv is a weird format. It has never been officially documented by Microsoft and still there is no hard standards for any library to follow. Especially around quoting strings and new lines (outside of unquoted ones which mark new row of a datatable)


It should work fine for both windows and unix new lines quoted between regular quotation mark ( " ).

If you want to get rid of new lines you can use regex regex replace with above expression, and replace with \t - which will be tab.

Toggle window snippet (show / hide / bring to front) with Autohotkey

This piece of code toggles any window. It will * RESTORE if window is minimized, * Bring to the top so window is foremost if it is behind other windows, * Minimize if window is active and on top,

Quick toggle any window.

This piece of code toggles any window [Autohotkey].

It will

  • RESTORE if window is minimized
  • Bring to the top so window is foremost if it is behind other windows
  • MINIMIZE if window is currently active and on top

Spotify is a being toggled in the below code, just as an example.

WindowTitle = ahk_exe Spotify.exe ;just as an example 

if (ID := WinExist(WindowTitle)){
WinGet, state, MinMax, %WindowTitle%

if (state = -1) {
WinRestore %WindowTitle%
} Else {
WinGetPos , X, Y, , , %WindowTitle%
If ( WinActive(WindowTitle))
WinMinimize, %WindowTitle%
WinActivate, %WindowTitle%

Online code utilities

List of helpful online code tools and utilities. Mirrored from github user fghber

This has been mirrored from github - fghber's gist


ideone Ideone is an online compiler and debugging tool which allows youto compile source code and execute it online in more than 60 programming languages and share links to the code. Like ideaone, can also install missing Python packages.
Onlilne GDB Online compiler and debugger forC, C++, Python, Java, PHP, Ruby, Perl, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog, and more.
Coding Ground Advanced IDEs for C/C++, C#, GO, Java, PHP, Perl, Python, Octave/MATLOAB, R, Ruby, Scala, and compiler/interpreter for many other languages and frameworks.
JDOODLE very similar to ideone but a somewhat different set of languagse/compilers.

Dedicated: JSFiddle Online JavaScript, CSS, HTML or CoffeeScript code editor. Option to add various web frameworks. .NET Fiddle Online compiler for C#, VB.NET, and F# with .NET 4.5 & Roslyn 2.0. Option to install additional nuget packages.

(Cloud workspaces:,


Online Tester & Code Generator

regex101 Online regex tester for PHP, PCRE, JavaScript and Python that highlights pattern and matches on the fly. Online regex tester with gut regex replace and explain functionality. Can show neat expression diagrams (not active anymore). also shows expression diagrams. Allows to optimize patterns (I guess this is based on this Perl's Regexp::Optimizer).

Libraries Regular Expression Library. Currently has 7601 expressions from 2492 contributors (most are subpar IMHO).


txt2re: regular expression generator (with code generator for perl php python java javascript coldfusion c c++ ruby vb vbscript j# c#

.NET Regex

Java Regex




htaccess tester

Google Analytics Regex Tester (and a general GA RE usage guide)

Regex Reverse Pattern generator

sre_yield: generate all values that can match a given regular expression, or count possible matches efficiently
Xeger: Java library for generating strings that match a specific regular expression.
PyXeger: Java library for generating strings that match a specific regular expression.

General Languages



PHP Sandbox: Allows to test PHP code on many php versions. allows to run over 200 different PHP versions (including HHVM, etc.) in parallel - excellent for version compatibility tests An online IDE that supports many languages (free for personal use). A PHP online IDE with some extra resources like code search (saved, external code).

EXREX is a command line tool and python module that generates all - or random - matching strings to a given regular expression and more.




Query test:
Sort array:
Generate C# classes from JSON: (Desktop tool: FromJson(to XML, HTML, CSV, SQL, YAML), ToJson, JsonTools (Lint, Viewer, Format, Path Analyzer)

SQL (MySQL, Oracle, PosgreSQL, SQLite, MS SQL 2014) (MySQL, Oracle)

SQL Formater (online formatting service) (Poor Man's SQL Formatter online, download for VS, SMSS, Np++, etc.).


Code beautifier & Syntax Highlither Syntax Highlither for varius languages (useful for HTML & RTF text)

Character Set Conversion


Arul's network and other technical utilities: View your IP, country, ISP name, OS, browser/UA.
Convert IP address to hostname and vice versa, text case convert, UNIX timestamp to date, hash generator

Record and share Linux/Mac terminal sessions:

Vanilla JS XPath query function

Snippet with function making DOM XPath queries easy in the browser.

Method 1

Using XPathEvaluator with start node and multiple results.

function evaluateXPath(aNode, aExpr) {
var xpe = new XPathEvaluator();
var nsResolver = xpe.createNSResolver(aNode.ownerDocument == null ?
aNode.documentElement : aNode.ownerDocument.documentElement);
var result = xpe.evaluate(aExpr, aNode, nsResolver, 0, null);
var found = [];
var res;
while (res = result.iterateNext())
return found;

Sample query:

evaluateXPath(document, '//button[@title="Edit" or @title="Add"]')

/* Result:
0: button#49431283ecf54dbaba1fcd8bf735af41.WABN.WEBN.WIMO.WNTN.WO5M
length: 1
__proto__: Array(0)

Method 2

Single node, always against document using XPathEvaluator

function getElementByXPath(xpath) {
return new XPathEvaluator()
.evaluate(document, XPathResult.FIRST_ORDERED_NODE_TYPE)

console.log( getElementByXPath("//html[1]/body[1]/div[1]") );

Method 3

Single node, against document using document.evaluate

function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

console.log( getElementByXpath("//html[1]/body[1]/div[1]") );function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

console.log( getElementByXpath("//html[1]/body[1]/div[1]") );

XPath cheatsheet

Very handy cheatsheet covering xpath concepts and comparing it to css selectors equivalents when possible

This has been copied from here:


Xpath test bed

Test queries in the Xpath test bed:

Xpath test bed (

Browser console


Works in Firefox and Chrome.


Descendant selectors

div p//div//p?
ul > li//ul/li?
ul > li > a//ul/li/a
div > *//div/*
:root > body/body

{: .xp}

Attribute selectors

.class//*[@class="class"] ...kinda
a[href^='/']//a[starts-with(@href, '/')]?
a[href$='pdf']//a[ends-with(@href, '.pdf')]
a[href*='://']//a[contains(@href, '://')]
a[rel~='help']//a[contains(@rel, 'help')] ...kinda

{: .xp}

Order selectors

ul > li:first-child//ul/li[1]?
ul > li:nth-child(2)//ul/li[2]
ul > li:last-child//ul/li[last()]

{: .xp}


h1 ~ ul//h1/following-sibling::ul?
h1 + ul//h1/following-sibling::ul[1]
h1 ~ #id//h1/following-sibling::[@id="id"]

{: .xp}


$('ul > li').parent()//ul/li/..?

{: .xp}

Other things

Text match//button[text()="Submit"]?
Text match (substring)//button[contains(text(),"Go")]
Arithmetic//product[@price > 2.50]
Has children//ul[*]
Has children (specific)//ul[li]
Or logic//a[@name or @href]?
Union (joins results)//a | //div?

{: .xp}

Class check

//div[contains(concat(' ',normalize-space(@class),' '),' foobar ')]

Xpath doesn't have the "check if part of space-separated list" operator, so this is the workaround (source).


Steps and axes


{: .-css-breakdown}



{: .-headers}

Begin your expression with any of these.



{: .-headers}

Separate your steps with /. Use two (//) if you don't want to select direct children.



A step may have an element name (div) and predicates ([...]). Both are optional.
They can also be these other things:

//a/text()     #=> "Go home"
//a/@href #=> "index.html"
//a/* #=> All a's child elements




Restricts a nodeset only if some condition is true. They can be chained.


# Comparison
//a[@id = "xyz"]
//a[@id != "xyz"]
//a[@price > 25]
# Logic (and/or)
//div[@id="head" and position()=2]
//div[(x and y) or not(z)]

Use comparison and logic operators to make conditionals.

Using nodes

# Use them inside functions
//ul[count(li) > 2]
//ul[count(li[@class='hide']) > 0]
# This returns `<ul>` that has a `<li>` child

You can use nodes inside predicates.


//a[1]                  # first <a>
//a[last()] # last <a>
//ol/li[2] # second <li>
//ol/li[position()=2] # same as above
//ol/li[position()>1] # :not(:first-child)

Use [] with a number, or last() or position().

Chaining order


Order is significant, these two are different.

Nesting predicates


This returns <section> if it has an <h1> descendant with id='hi'.


Node functions

name()                     # //[starts-with(name(), 'h')]
text() # //button[text()="Submit"]
# //button/text()
count()                    # //table[count(tr)=1]
position() # //ol/li[position()=2]

Boolean functions

not(expr)                  # button[not(starts-with(text(),"Submit"))]

String functions

contains()                 # font[contains(@class,"head")]
starts-with() # font[starts-with(@class,"head")]
ends-with() # font[ends-with(@class,"head")]
substring(str, start, len)
substring-before("01/02", "/") #=> 01
substring-after("01/02", "/") #=> 02

Type conversion



Using axes

//ul/li                       # ul > li
//ul/child::li # ul > li (same)
//ul/following-sibling::li # ul ~ li
//ul/descendant-or-self::li # ul li
//ul/ancestor-or-self::li # $('ul').closest('li')

Steps of an expression are separated by /, usually used to pick child nodes. That's not always true: you can specify a different "axis" with ::.

| // | ul | /child:: | li |
| Axis | Step | Axis | Step |
{: .-css-breakdown}

Child axis

# both the same

child:: is the default axis. This makes //a/b/c work.

# both the same
# this works because `child::li` is truthy, so the predicate succeeds
# both the same
//ul[count(li) > 2]
//ul[count(child::li) > 2]

Descendant-or-self axis

# both the same

// is short for the descendant-or-self:: axis.

# both the same

Other axes

attribute@@href is short for attribute::href
childdiv is short for child::div
descendant-or-self//// is short for /descendant-or-self::node()/
self.. is short for self::node()
parent.... is short for parent::node()

{: .-headers}

There are other axes you can use.


//a | //span

Use | to join two expressions.

More examples


//*                 # all elements
count(//*) # count all elements
(//h1)[1]/text() # text of the first h1 heading
//li[span] # find a <li> with an <span> inside it
# ...expands to //li[child::span]
//ul/li/.. # use .. to select a parent

Find a parent


Finds a <section> that directly contains h1#section-name


Finds a <section> that contains h1#section-name.
(Same as above, but uses descendant-or-self instead of child)



Works like jQuery's $().closest('.box').


//item[@price > 2*@discount]

Finds <item> and check its attributes


{: .-one-column}

More helpful resources:

Ultimate slugify function

Ultimate slugify function

Best approach I could find if you don't want any additional libs for this transformation.

function slugify(string) {
const a = 'àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;'
const b = 'aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------'
const p = new RegExp(a.split('').join('|'), 'g')

return string.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(p, c => b.charAt(a.indexOf(c))) // Replace special characters
.replace(/&/g, '-and-') // Replace & with 'and'
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, '') // Trim - from end of text

Iterating through nested JavaScript object and extracting data.

How to iterate and extract data from nested JSON in case there is no structure or limit of depth.

This one really got me. Mostly because i spent 40 minutes on mindless looking for ready to take solution.
After checking dozen of lodash methods almost on random hoping it will just work i realized i had to invest some effort ;)

But once you get past the scary bit that "IT CAN GO FOREVER", and realize that recursive function is what you need - it is really trivial.

I needed to parse resulting JSON from chrome extensions API chrome.bookmarks.get and extract folder names and their ids.

Retrieved type is called BookmarkTreeNode.

It is basically simple object with some string and integer props, but one property named'children' can be an array of nested - children nodes. It is a property of object which usually represent parent folder.

So what we need to do is to check the properties of currently iterated object and first, save folder name and id to our empty array (as this was my goal in the first place) and check if among properties is another object to iterate.
And that's it.

const links = require('./links.json'); 
let folders = []; // folders will be pushed here

const checkObj = obj => {
if ('dateGroupModified' in obj) // 'dateGroupModified' is present only for folder node
folders.push({ title: obj.title, id: });
Object.keys(obj).forEach(key => {
if (typeof obj[key] == 'object') checkObj(obj[key]);