Just to clarify, regexes exist in every modern programming language, not just javascript. They're often permitted in shell commands and even configuration files for many utilities. While there are some differences between their engines, the vast majority of use cases will have the same syntax across platforms. It's a great skill learn at least at a basic level.
They're even commonly used in IDEs and text editors (E.g. in vscode, in the find/replace dialog, there is a .* button that enables regex). This can get REALLY powerful when you need to make a change to a large number of similar but different values.
For example, let's say you copy/paste a table from a browser, you'll get something like:
first one
second two
third three
If you want to convert it to a block of JSON, you could spend an hour surrounding the keys and values with quotes, and replacing the tab with :. OR, you can use find with:
([^\t]+)\t(.*)
which says: "find a group of stuff that is not a tab (group 1), followed by a tab, followed by the rest of the line (group 2)".
Just to clarify, regexes exist in every modern programming language, not just javascript. They're often permitted in shell commands and even configuration files for many utilities. While there are some differences between their engines, the vast majority of use cases will have the same syntax across platforms. It's a great skill learn at least at a basic level.
They're even commonly used in IDEs and text editors (E.g. in vscode, in the find/replace dialog, there is a
.*
button that enables regex). This can get REALLY powerful when you need to make a change to a large number of similar but different values.For example, let's say you copy/paste a table from a browser, you'll get something like:
If you want to convert it to a block of JSON, you could spend an hour surrounding the keys and values with quotes, and replacing the tab with
:
. OR, you can use find with:which says: "find a group of stuff that is not a tab (group 1), followed by a tab, followed by the rest of the line (group 2)".
Then replace with:
which says:
"
)": "
)",
)Presto!
Now you have 59 extra minutes. ;)