From 84d1b1bb66429d5b8435c502069693c2465b16eb Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 15 Apr 2020 11:25:58 +0000 Subject: [PATCH] Travis build: 128 --- blog_data/snippetList.json | 16 ++++++++++++++++ blog_data/snippets.json | 26 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/blog_data/snippetList.json b/blog_data/snippetList.json index 738f7c3fb..6208cb2e1 100644 --- a/blog_data/snippetList.json +++ b/blog_data/snippetList.json @@ -30,6 +30,22 @@ "hash": "ebc2337246ca7925e763034b8f5718f6276afd9252856cad56eff5f6d6ba25f1" } }, + { + "id": "6-javascript-regexp-tricks", + "type": "snippetListing", + "title": "6 JavaScript Regular Expression features you can use today", + "attributes": { + "text": "Regular expressions, while very powerful, are notoriously hard to master. Here are 6 useful features that can help you start using them in your JavaScript projects:\n\n**Capturing groups**\n\nCapturing groups allow you to get specific parts of the matched string, simply by wrapping part of the regular expression in parentheses `(...)`:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(JavaScript) is a (.*)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'JavaScript',\n 2: 'programming language'\n ]\n*/\n```\n\n**Non-capturing groups**\n\nNon-capturing groups are used for matching something without capturing it, like an either/or matching group that you do not really need. They are defined similarly to capturing groups, but prefixed with `?:`:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(?:JavaScript|Python) is a (.+)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'programming language'\n ]\n*/\n```\n\n**Named capturing groups**\n\nNamed capturing groups allow you to name a capturing group, by prefixing it with ``:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(?.+) is a (?.+)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'JavaScript',\n 2: 'programming language',\n groups: {\n subject: 'JavaScript,\n description: 'programming language'\n }\n ]\n*/\n```\n\n**Capturing group backreferences**\n\nBackreferences help you write shorter regular expressions, by repeating an existing capturing group, using `\\1`, `\\2` etc. Similarly, you can also repeat named capturing groups using `\\k`:\n\n```js\nconst str = 'JavaScript is a programming language - an awesome programming language JavaScript is';\n/(.+) is a (?.+) - an awesome \\k \\1 is/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language - an awesome programming language JavaScript is',\n 1: 'JavaScript',\n 2: 'programming language',\n groups: {\n subject: 'JavaScript,\n description: 'programming language'\n }\n ]\n*/\n```\n\n**Lookaheads**\n\nLookaheads allow you to check if something is followed by a certain pattern, without actually matching it. You can create positive lookaheads using `?=` and negative lookaheads using `?!`:\n\n```js\nconst str = 'JavaScript is not the same as Java and you should remember that';\n/Java(?=Script)(.*)/.exec(str);\n/*\n [\n 0: 'JavaScript is not the same as Java and you should remember that',\n 1: 'Script is not the same as Java and you should remember that'\n ]\n*/\n\n/Java(?!Script)(.*)/.exec(str);\n/*\n [\n 0: 'Java and you should remember that',\n 1: ' and you should remember that'\n ]\n*/\n```\n\n**Unicode characters**\n\nFinally, you can match unicode characters, using `/p{...}` and the `/u` flag. Examples include, but are not limited to `{Emoji}`, `{Math_Symbols}` and `{Script=Greek}`:\n\n```js\nconst str = 'Greek looks like this: γεια';\n/\\p{Script=Greek}+/u.exec(str);\n/*\n [\n 0: 'γεια'\n ]\n*/\n```\n\n**Image credit:** [Kace Rodriguez](https://unsplash.com/@kace?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/code?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)\n", + "tags": [ + "javascript", + "string", + "regexp" + ] + }, + "meta": { + "hash": "2e6e5d06cb22bf4dfed8489172861f9361129f1fb83cf503d4817b332ae459bf" + } + }, { "id": "7-chrome-extensions-for-web-developers", "type": "snippetListing", diff --git a/blog_data/snippets.json b/blog_data/snippets.json index 3b7a69520..998c3a613 100644 --- a/blog_data/snippets.json +++ b/blog_data/snippets.json @@ -50,6 +50,32 @@ "authorCount": 2 } }, + { + "id": "6-javascript-regexp-tricks", + "title": "6 JavaScript Regular Expression features you can use today", + "type": "blog.story", + "attributes": { + "fileName": "6-javascript-regexp-tricks.md", + "cover": "blog_images/6-javascript-regexp-tricks.jpg", + "excerpt": "Regular expressions, while very powerful, are notoriously hard to master. Start using them in your JavaScript code by understanding these 6 features.", + "authors": [ + "chalarangelo" + ], + "text": "Regular expressions, while very powerful, are notoriously hard to master. Here are 6 useful features that can help you start using them in your JavaScript projects:\n\n**Capturing groups**\n\nCapturing groups allow you to get specific parts of the matched string, simply by wrapping part of the regular expression in parentheses `(...)`:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(JavaScript) is a (.*)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'JavaScript',\n 2: 'programming language'\n ]\n*/\n```\n\n**Non-capturing groups**\n\nNon-capturing groups are used for matching something without capturing it, like an either/or matching group that you do not really need. They are defined similarly to capturing groups, but prefixed with `?:`:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(?:JavaScript|Python) is a (.+)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'programming language'\n ]\n*/\n```\n\n**Named capturing groups**\n\nNamed capturing groups allow you to name a capturing group, by prefixing it with ``:\n\n```js\nconst str = 'JavaScript is a programming language';\n/(?.+) is a (?.+)/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language',\n 1: 'JavaScript',\n 2: 'programming language',\n groups: {\n subject: 'JavaScript,\n description: 'programming language'\n }\n ]\n*/\n```\n\n**Capturing group backreferences**\n\nBackreferences help you write shorter regular expressions, by repeating an existing capturing group, using `\\1`, `\\2` etc. Similarly, you can also repeat named capturing groups using `\\k`:\n\n```js\nconst str = 'JavaScript is a programming language - an awesome programming language JavaScript is';\n/(.+) is a (?.+) - an awesome \\k \\1 is/.exec(str);\n/*\n [\n 0: 'JavaScript is a programming language - an awesome programming language JavaScript is',\n 1: 'JavaScript',\n 2: 'programming language',\n groups: {\n subject: 'JavaScript,\n description: 'programming language'\n }\n ]\n*/\n```\n\n**Lookaheads**\n\nLookaheads allow you to check if something is followed by a certain pattern, without actually matching it. You can create positive lookaheads using `?=` and negative lookaheads using `?!`:\n\n```js\nconst str = 'JavaScript is not the same as Java and you should remember that';\n/Java(?=Script)(.*)/.exec(str);\n/*\n [\n 0: 'JavaScript is not the same as Java and you should remember that',\n 1: 'Script is not the same as Java and you should remember that'\n ]\n*/\n\n/Java(?!Script)(.*)/.exec(str);\n/*\n [\n 0: 'Java and you should remember that',\n 1: ' and you should remember that'\n ]\n*/\n```\n\n**Unicode characters**\n\nFinally, you can match unicode characters, using `/p{...}` and the `/u` flag. Examples include, but are not limited to `{Emoji}`, `{Math_Symbols}` and `{Script=Greek}`:\n\n```js\nconst str = 'Greek looks like this: γεια';\n/\\p{Script=Greek}+/u.exec(str);\n/*\n [\n 0: 'γεια'\n ]\n*/\n```\n\n**Image credit:** [Kace Rodriguez](https://unsplash.com/@kace?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/s/photos/code?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)\n", + "tags": [ + "javascript", + "string", + "regexp" + ] + }, + "meta": { + "hash": "2e6e5d06cb22bf4dfed8489172861f9361129f1fb83cf503d4817b332ae459bf", + "firstSeen": "1586949890", + "lastUpdated": "1586949890", + "updateCount": 2, + "authorCount": 2 + } + }, { "id": "7-chrome-extensions-for-web-developers", "title": "7 essential Chrome extensions for web developers",