From 5e8edafbe1523ab3e353c014e848dfcdd0cdcfd3 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Wed, 24 Jul 2019 11:58:06 +0300 Subject: [PATCH] regexp task --- .../solution.md | 0 .../task.md | 2 +- .../solution.md | 18 ------------ .../3-find-decimal-positive-numbers/task.md | 12 -------- .../1-find-non-negative-integers/solution.md | 28 +++++++++++++++++++ .../1-find-non-negative-integers/task.md | 14 ++++++++++ 6 files changed, 43 insertions(+), 31 deletions(-) rename 9-regular-expressions/09-regexp-groups/{4-find-decimal-numbers => 2-find-decimal-numbers}/solution.md (100%) rename 9-regular-expressions/09-regexp-groups/{4-find-decimal-numbers => 2-find-decimal-numbers}/task.md (91%) delete mode 100644 9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md delete mode 100644 9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md create mode 100644 9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md create mode 100644 9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/task.md diff --git a/9-regular-expressions/09-regexp-groups/4-find-decimal-numbers/solution.md b/9-regular-expressions/09-regexp-groups/2-find-decimal-numbers/solution.md similarity index 100% rename from 9-regular-expressions/09-regexp-groups/4-find-decimal-numbers/solution.md rename to 9-regular-expressions/09-regexp-groups/2-find-decimal-numbers/solution.md diff --git a/9-regular-expressions/09-regexp-groups/4-find-decimal-numbers/task.md b/9-regular-expressions/09-regexp-groups/2-find-decimal-numbers/task.md similarity index 91% rename from 9-regular-expressions/09-regexp-groups/4-find-decimal-numbers/task.md rename to 9-regular-expressions/09-regexp-groups/2-find-decimal-numbers/task.md index 121a18a4..44656384 100644 --- a/9-regular-expressions/09-regexp-groups/4-find-decimal-numbers/task.md +++ b/9-regular-expressions/09-regexp-groups/2-find-decimal-numbers/task.md @@ -1,4 +1,4 @@ -# Find all numbers +# Find decimal numbers Write a regexp that looks for all decimal numbers including integer ones, with the floating point and negative ones. diff --git a/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md b/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md deleted file mode 100644 index c99a95bb..00000000 --- a/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/solution.md +++ /dev/null @@ -1,18 +0,0 @@ - -An non-negative integer number is `pattern:\d+`. A zero `0` can't be the first digit, but we should allow it in further digits. - -So that gives us `pattern:[1-9]\d*`. - -A decimal part is: `pattern:\.\d+`. - -Because the decimal part is optional, let's put it in parentheses with the quantifier `pattern:?`. - -Finally we have the regexp: `pattern:[1-9]\d*(\.\d+)?`: - -```js run -let reg = /[1-9]\d*(\.\d+)?/g; - -let str = "1.5 0 -5 12. 123.4."; - -alert( str.match(reg) ); // 1.5, 0, 12, 123.4 -``` diff --git a/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md b/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md deleted file mode 100644 index ad8c81ea..00000000 --- a/9-regular-expressions/09-regexp-groups/3-find-decimal-positive-numbers/task.md +++ /dev/null @@ -1,12 +0,0 @@ -# Find positive numbers - -Create a regexp that looks for positive numbers, including those without a decimal point. - -An example of use: -```js -let reg = /your regexp/g; - -let str = "1.5 0 -5 12. 123.4."; - -alert( str.match(reg) ); // 1.5, 12, 123.4 (ignores 0 and -5) -``` diff --git a/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md new file mode 100644 index 00000000..3b5ceda1 --- /dev/null +++ b/9-regular-expressions/14-regexp-lookahead-lookbehind/1-find-non-negative-integers/solution.md @@ -0,0 +1,28 @@ + +A number is `pattern:\d+`. + +We can exclude negatives by prepending it with the negative lookahead: `pattern:(?