Revision da9ff9c4
Added by Andreas Müller about 5 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java | ||
---|---|---|
467 | 467 |
return false; |
468 | 468 |
} |
469 | 469 |
|
470 |
/** |
|
471 |
* Removes all non-word character (i.e. *, @, %, line breaks, etc.) |
|
472 |
* from the given string |
|
473 |
* @param string the string which should be trimmed |
|
474 |
* @return the trimmed string |
|
475 |
*/ |
|
476 |
static public String trimNonWordCharacters(String string){ |
|
477 |
return replaceNonWordCharacters(string, ""); |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Replaces all non-word character (i.e. *, @, %, line breaks, etc.) |
|
482 |
* with the given replacement string |
|
483 |
* @param string the string which should be trimmed |
|
484 |
* @param replacement the replacement for the non-word characters |
|
485 |
* @return the trimmed string |
|
486 |
*/ |
|
487 |
static public String replaceNonWordCharacters(String string, String replacement){ |
|
488 |
return string.replaceAll("\\W", replacement); |
|
489 |
} |
|
490 |
|
|
491 | 470 |
/** |
492 | 471 |
* Returns <code>false</code> if string is null, "" or string.trim() is "" |
493 | 472 |
* @see isNotEmpty(String string) |
... | ... | |
686 | 665 |
return true; |
687 | 666 |
} |
688 | 667 |
|
668 |
/** |
|
669 |
* Transforms a search string which allows wildcard "*" into a |
|
670 |
* java regular expression such that all other characters are handled as normal text. |
|
671 |
* @param regEx |
|
672 |
* @return |
|
673 |
*/ |
|
674 |
public static String quoteRegExWithWildcard(String regEx){ |
|
675 |
return Pattern.quote(regEx).replace("*", "\\E.*\\Q").replace("\\Q\\E", ""); |
|
676 |
} |
|
677 |
|
|
689 | 678 |
} |
Also available in: Unified diff
ref #8041 correct regex quotation method implemented in CdmUtils