|
| 1 | +package com.bobocode.se; |
| 2 | + |
| 3 | +import com.bobocode.util.ExerciseNotCompletedException; |
| 4 | + |
| 5 | +import java.util.regex.Pattern; |
| 6 | + |
| 7 | +/** |
| 8 | + * {@link CrazyRegex} is an exercise class. Each method returns Pattern class which |
| 9 | + * should be created using regex expression. Every method that is not implemented yet |
| 10 | + * throws {@link ExerciseNotCompletedException} |
| 11 | + * @author Andriy Paliychuk |
| 12 | + * TODO: remove exception and implement each method of this class using java.util.regex.Pattern |
| 13 | + */ |
| 14 | +public class CrazyRegex { |
| 15 | + |
| 16 | + /** |
| 17 | + * A Pattern that that finds all words "Curiosity" in text |
| 18 | + * |
| 19 | + * @return a pattern that looks for the word "Curiosity" |
| 20 | + */ |
| 21 | + public Pattern findSpecificWord() { |
| 22 | + throw new ExerciseNotCompletedException(); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * A Pattern that finds first word in text |
| 27 | + * |
| 28 | + * @return a pattern that looks for the first word in text |
| 29 | + */ |
| 30 | + public Pattern findFirstWord() { |
| 31 | + throw new ExerciseNotCompletedException(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * A Pattern that finds last word in text |
| 36 | + * |
| 37 | + * @return a pattern that looks for the last word in text |
| 38 | + */ |
| 39 | + public Pattern findLastWord() { |
| 40 | + throw new ExerciseNotCompletedException(); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * A Pattern that finds all numbers in text. When we have "555-555", "(555)555" and "30th" in text |
| 45 | + * our pattern must grab all that numbers: |
| 46 | + * "555" - four times, and one "30" |
| 47 | + * |
| 48 | + * @return a pattern that looks for numbers |
| 49 | + */ |
| 50 | + public Pattern findAllNumbers() { |
| 51 | + throw new ExerciseNotCompletedException(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * A Pattern that finds all dates. For instance: "1971-11-23" |
| 56 | + * |
| 57 | + * @return a pattern that looks for dates |
| 58 | + */ |
| 59 | + public Pattern findDates() { |
| 60 | + throw new ExerciseNotCompletedException(); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * A Pattern that finds different variations of word "color". |
| 65 | + * We are looking for: "color", "colour", "colors", "colours" |
| 66 | + * |
| 67 | + * @return a pattern that looks for different variations of word "color" |
| 68 | + */ |
| 69 | + public Pattern findDifferentSpellingsOfColor() { |
| 70 | + throw new ExerciseNotCompletedException(); |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * A Pattern that finds all zip codes in text. |
| 75 | + * Zip code is a 5-digit number without any characters or special symbols. |
| 76 | + * For example: 72300 |
| 77 | + * |
| 78 | + * @return a pattern that looks for zip codes |
| 79 | + */ |
| 80 | + public Pattern findZipCodes() { |
| 81 | + throw new ExerciseNotCompletedException(); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * A Pattern that finds different variations of word "link". |
| 86 | + * We are looking for: "lynk", "link", "l nk", "l(nk" |
| 87 | + * |
| 88 | + * @return a pattern that looks for different variations of word "link" |
| 89 | + */ |
| 90 | + public Pattern findDifferentSpellingsOfLink() { |
| 91 | + throw new ExerciseNotCompletedException(); |
| 92 | + } |
| 93 | + |
| 94 | + /** |
| 95 | + * A Pattern that finds phone numbers. |
| 96 | + * For example: "555-555-5555" |
| 97 | + * |
| 98 | + * @return a pattern that looks for phone numbers |
| 99 | + */ |
| 100 | + public Pattern findSimplePhoneNumber() { |
| 101 | + throw new ExerciseNotCompletedException(); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * A Pattern that finds numbers with following requirements: |
| 106 | + * - inside the number can be only digits from 0 to 5 |
| 107 | + * - length 3 |
| 108 | + * |
| 109 | + * @return a pattern that looks for numbers with length 3 and digits from 0 to 5 in the middle |
| 110 | + */ |
| 111 | + public Pattern findNumbersFromZeroToFiveWithLengthThree() { |
| 112 | + throw new ExerciseNotCompletedException(); |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * A Pattern that finds all words in text that have length 5 |
| 117 | + * |
| 118 | + * @return a pattern that looks for the words that have length 5 |
| 119 | + */ |
| 120 | + public Pattern findAllWordsWithFiveLength() { |
| 121 | + throw new ExerciseNotCompletedException(); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * A Pattern that finds words and numbers with following constraints: |
| 126 | + * - not shorter than two symbols |
| 127 | + * - not longer than three symbols |
| 128 | + * |
| 129 | + * @return a pattern that looks for words and numbers that not shorter 2 and not longer 3 |
| 130 | + */ |
| 131 | + public Pattern findAllLettersAndDigitsWithLengthThree() { |
| 132 | + throw new ExerciseNotCompletedException(); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * A Pattern that finds all words that begin with capital letter |
| 137 | + * |
| 138 | + * @return a pattern that looks for the words that begin with capital letter |
| 139 | + */ |
| 140 | + public Pattern findAllWordsWhichBeginWithCapitalLetter() { |
| 141 | + throw new ExerciseNotCompletedException(); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * A Pattern that finds only the following abbreviation: |
| 146 | + * - AK, AL, AR, AZ, CA, CO, CT, PR, PA, PD |
| 147 | + * |
| 148 | + * @return a pattern that looks for the abbreviations above |
| 149 | + */ |
| 150 | + public Pattern findAbbreviation() { |
| 151 | + throw new ExerciseNotCompletedException(); |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * A Pattern that finds all open braces |
| 156 | + * |
| 157 | + * @return a pattern that looks for all open braces |
| 158 | + */ |
| 159 | + public Pattern findAllOpenBraces() { |
| 160 | + throw new ExerciseNotCompletedException(); |
| 161 | + } |
| 162 | + |
| 163 | + /** |
| 164 | + * A Pattern that finds everything inside [] |
| 165 | + * |
| 166 | + * @return a pattern that looks for everything inside [] |
| 167 | + */ |
| 168 | + public Pattern findOnlyResources() { |
| 169 | + throw new ExerciseNotCompletedException(); |
| 170 | + } |
| 171 | + |
| 172 | + /** |
| 173 | + * A Pattern that finds all https links in note.txt |
| 174 | + * |
| 175 | + * @return a pattern that looks for all https links in note.txt |
| 176 | + */ |
| 177 | + public Pattern findOnlyLinksInNote() { |
| 178 | + throw new ExerciseNotCompletedException(); |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * A Pattern that finds all http links in nasa.json |
| 183 | + * |
| 184 | + * @return a pattern that looks for all http links in nasa.json |
| 185 | + */ |
| 186 | + public Pattern findOnlyLinksInJson() { |
| 187 | + throw new ExerciseNotCompletedException(); |
| 188 | + } |
| 189 | + |
| 190 | + /** |
| 191 | + * A Pattern that finds all .com, .net and .edu emails |
| 192 | + * |
| 193 | + * @return a pattern that looks for all .com, .net and .edu emails |
| 194 | + */ |
| 195 | + public Pattern findAllEmails() { |
| 196 | + throw new ExerciseNotCompletedException(); |
| 197 | + } |
| 198 | + |
| 199 | + /** |
| 200 | + * A Pattern that finds the following examples of phone numbers: |
| 201 | + * - 555-555-5555 |
| 202 | + * - 555.555.5555 |
| 203 | + * - (555)555-5555 |
| 204 | + * |
| 205 | + * @return a pattern that looks for phone numbers patterns above |
| 206 | + */ |
| 207 | + public Pattern findAllPatternsForPhoneNumbers() { |
| 208 | + throw new ExerciseNotCompletedException(); |
| 209 | + } |
| 210 | + |
| 211 | + /** |
| 212 | + * A Pattern that finds only duplicates |
| 213 | + * |
| 214 | + * @return a pattern that looks for duplicates |
| 215 | + */ |
| 216 | + public Pattern findOnlyDuplicates() { |
| 217 | + throw new ExerciseNotCompletedException(); |
| 218 | + } |
| 219 | + |
| 220 | + /** |
| 221 | + * You have a text where all names recorded as first name, last name. |
| 222 | + * Create matcher and use method replaceAll to record that names as: |
| 223 | + * - last name first name |
| 224 | + * |
| 225 | + * @return String where all names recorded as last name first name |
| 226 | + */ |
| 227 | + public String replaceFirstAndLastNames(String names) { |
| 228 | + throw new ExerciseNotCompletedException(); |
| 229 | + } |
| 230 | + |
| 231 | + /** |
| 232 | + * You have a text with phone numbers. |
| 233 | + * Create matcher and use method replaceAll to replace last digits: |
| 234 | + * - 555-XXX-XXXX |
| 235 | + * |
| 236 | + * @return String where in all phone numbers last 7 digits replaced to X |
| 237 | + */ |
| 238 | + public String replaceLastSevenDigitsOfPhoneNumberToX(String phones) { |
| 239 | + throw new ExerciseNotCompletedException(); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * You have a text with resources and links to those resources: |
| 244 | + * - [Bobocode](https://www.bobocode.com) |
| 245 | + * Create matcher and use method replaceAll to get the following result: |
| 246 | + * - <a href="https://www.bobocode.com">Bobocode</a> |
| 247 | + * |
| 248 | + * @return String where all resources embraced in href |
| 249 | + */ |
| 250 | + public String insertLinksAndResourcesIntoHref(String links) { |
| 251 | + throw new ExerciseNotCompletedException(); |
| 252 | + } |
| 253 | + |
| 254 | + |
| 255 | +} |
0 commit comments