From 158878552a5d17ab567ae055f368489c499b59c2 Mon Sep 17 00:00:00 2001 From: Riadh Date: Mon, 30 Sep 2019 16:12:09 +0200 Subject: [PATCH 1/6] Fix snake snippet --- snippets/snake.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/snippets/snake.md b/snippets/snake.md index efb49396e..480d87fc7 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -11,15 +11,13 @@ Break the string into words and combine them adding `_-_` as a separator, using import re def snake(str): - return re.sub(r"(\s|_|-)+","-", - re.sub(r"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+", - lambda mo: mo.group(0).lower(),str) - ) + return '-'.join(re.sub('([A-Z][a-z]+)', r' \1', + re.sub('([A-Z]+)', r' \1', str)).split()).lower() ``` ```py -snake('camelCase'); # 'camel_case' -snake('some text'); # 'some_text' -snake('some-mixed_string With spaces_underscores-and-hyphens'); # 'some_mixed_string_with_spaces_underscores_and_hyphens' -snake('AllThe-small Things'); # "all_the_smal_things" +snake('camelCase'); # 'camel-case' +snake('some text'); # 'some-text' +snake('some-mixed_string With spaces_underscores-and-hyphens'); # 'some-mixed-string-with-spaces-underscores-and-hyphens' +snake('AllThe-small Things'); # "all-the-smal-things" ``` From 2b70917df87ddecff61ebe96a289647ea3d5ab04 Mon Sep 17 00:00:00 2001 From: rfezzani Date: Mon, 30 Sep 2019 23:15:00 +0200 Subject: [PATCH 2/6] Fix snake case snippet --- snippets/snake.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/snake.md b/snippets/snake.md index 480d87fc7..f6ea75ac7 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -5,14 +5,14 @@ tags: string,regexp,intermediate Converts a string to snake case. -Break the string into words and combine them adding `_-_` as a separator, using a regexp. +Break the string into words and combine them adding underscore `_` as a separator, using a regexp. ```py import re def snake(str): - return '-'.join(re.sub('([A-Z][a-z]+)', r' \1', - re.sub('([A-Z]+)', r' \1', str)).split()).lower() + return '_'.join(re.sub('([A-Z][a-z]+)', r' \1', + re.sub('([A-Z]+)', r' \1', str)).split()).lower() ``` ```py From 05b09f6b4fb0a66939db968234d872caa3031701 Mon Sep 17 00:00:00 2001 From: rfezzani Date: Mon, 30 Sep 2019 23:18:39 +0200 Subject: [PATCH 3/6] Fix comments --- snippets/snake.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/snake.md b/snippets/snake.md index f6ea75ac7..48dde2233 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -16,8 +16,8 @@ def snake(str): ``` ```py -snake('camelCase'); # 'camel-case' -snake('some text'); # 'some-text' -snake('some-mixed_string With spaces_underscores-and-hyphens'); # 'some-mixed-string-with-spaces-underscores-and-hyphens' -snake('AllThe-small Things'); # "all-the-smal-things" +snake('camelCase'); # 'camel_case' +snake('some text'); # 'some_text' +snake('some-mixed_string With spaces_underscores-and-hyphens'); # 'some_mixed_string_with_spaces_underscores_and_hyphens' +snake('AllThe-small Things'); # "all_the_smal_things" ``` From 76ead087049e7a7e8ec5f229495aa830a4af1d62 Mon Sep 17 00:00:00 2001 From: Riadh Fezzani Date: Tue, 1 Oct 2019 14:46:42 +0200 Subject: [PATCH 4/6] Update snippets/snake.md Co-Authored-By: Angelos Chalaris --- snippets/snake.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/snake.md b/snippets/snake.md index fcbfd763d..10065206b 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -5,7 +5,7 @@ tags: string,regexp,intermediate Converts a string to snake case. -Break the string into words and combine them adding underscore `_` as a separator, using a regexp. +Break the string into words and combine them adding `_` as a separator, using a regexp. ```py import re From fe4bc649efb2ae2f02f65aed9043764aec804a2f Mon Sep 17 00:00:00 2001 From: Riadh Date: Tue, 1 Oct 2019 14:51:40 +0200 Subject: [PATCH 5/6] Fix the 'some_mixed_string_with_spaces_underscores_and_hyphens' case --- snippets/snake.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snippets/snake.md b/snippets/snake.md index 10065206b..a5b296c5e 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -12,7 +12,8 @@ import re def snake(str): return '_'.join(re.sub('([A-Z][a-z]+)', r' \1', - re.sub('([A-Z]+)', r' \1', str)).split()).lower() + re.sub('([A-Z]+)', r' \1', + str.replace('-', ' '))).split()).lower() ``` ```py From 6423f9810c7facce409c21029544aa397ba4a6a5 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 2 Oct 2019 09:42:29 +0300 Subject: [PATCH 6/6] Update snake.md --- snippets/snake.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/snake.md b/snippets/snake.md index a5b296c5e..4aa3f83fe 100644 --- a/snippets/snake.md +++ b/snippets/snake.md @@ -11,9 +11,9 @@ Break the string into words and combine them adding `_` as a separator, using a import re def snake(str): - return '_'.join(re.sub('([A-Z][a-z]+)', r' \1', - re.sub('([A-Z]+)', r' \1', - str.replace('-', ' '))).split()).lower() + return '_'.join(re.sub('([A-Z][a-z]+)', r' \1', + re.sub('([A-Z]+)', r' \1', + str.replace('-', ' '))).split()).lower() ``` ```py