@@ -313,14 +313,13 @@ public String stripAll(String string) {
313313 return stripRGB (stripSpecial (stripBukkit (string )));
314314 }
315315
316- /**
317- * A regular expression pattern that matches various color codes.
318- * <p>
319- * Supported formats include Bukkit color codes (using {@code &} or {@code §}),
320- * hexadecimal color codes in various notations, and legacy formats.
321- * </p>
322- */
323- private final String COLOR_PATTERN = "[&§][a-fk-or\\ d]|[{]#([a-f\\ d]{6})[}]|<#([a-f\\ d]{6})>|%#([a-f\\ d]{6})%|\\ [#([a-f\\ d]{6})]|&?#([a-f\\ d]{6})|&x([a-f\\ d]{6})" ;
316+ private final String COLOR_PATTERN = "(?i)" +
317+ "(?<!§x)(?<!§x§[0-9A-F])" +
318+ "(?<!§x(?:§[0-9A-F]){2})" +
319+ "(?<!§x(?:§[0-9A-F]){3})" +
320+ "(?<!§x(?:§[0-9A-F]){4})" +
321+ "(?<!§x(?:§[0-9A-F]){5})" +
322+ "(?>§x(?:§[0-9A-F]){6}|§[0-9A-FK-OR])" ;
324323
325324 /**
326325 * Checks if the provided string starts with a valid color code.
@@ -329,21 +328,21 @@ public String stripAll(String string) {
329328 * @return {@code true} if the string starts with a color code; {@code false} otherwise
330329 */
331330 public boolean startsWithColor (String string ) {
332- if (StringUtils .isBlank (string ))
333- return false ;
334- Pattern p = Pattern .compile ("^" + COLOR_PATTERN );
335- Matcher matcher = p .matcher (string );
331+ if (StringUtils .isBlank (string )) return false ;
332+ string = colorize (string );
333+ Matcher matcher = Pattern .compile ("^" + COLOR_PATTERN ).matcher (string );
336334 return matcher .find ();
337335 }
338336
339337 /**
340- * Retrieves the last color code found in the provided string.
338+ * Retrieves the end color code found in the provided string.
341339 *
342340 * @param string the string to search for color codes
343- * @return the last color code as a {@link String}, or {@code null} if none is found
341+ * @return the end color code as a {@link String}, or {@code null} if none is found
344342 */
345343 @ Nullable
346- public String getLastColor (String string ) {
344+ public String getEndColor (String string ) {
345+ string = colorize (string );
347346 Matcher matcher = Pattern .compile (COLOR_PATTERN ).matcher (string );
348347 String color = null ;
349348 while (matcher .find ()) color = matcher .group ();
0 commit comments