Код: Выделить всё
"StringExample0123".replaceAll("[0-9]","");
< /code>
Предыдущая строка кода будет выделять как «[]», так и «-», поскольку они являются частью форматирования Regex.customMethod("[0-9]");
< /code>
также выделен с помощью надлежащего синтаксиса Regex < /p>
В настоящее время Custommethod () имеет только документацию за замену, которую я пытался использовать, чтобы возиться и посмотреть, есть ли способ выделить парамец: < /p>
/**
* Replaces each substring of this string that matches the given [url=../util/regex/Pattern.html#sum]regular expression[/url] with the
* given replacement.
*
*
An invocation of this method of the form
* [i]str[/i]{@code .replaceAll(}[i]regex[/i]{@code ,} [i]repl[/i]{@code )}
* yields exactly the same result as the expression
*
*
*
* {@link java.util.regex.Pattern}.{@link
* java.util.regex.Pattern#compile(String) compile}([i]regex[/i]).{@link
* java.util.regex.Pattern#matcher(java.lang.CharSequence) matcher}([i]str[/i]).{@link
* java.util.regex.Matcher#replaceAll(String) replaceAll}([i]repl[/i])
* *
*
* Note that backslashes ({@code \}) and dollar signs ({@code $}) in the
* replacement string may cause the results to be different than if it were
* being treated as a literal replacement string; see
* {@link java.util.regex.Matcher#replaceAll Matcher.replaceAll}.
* Use {@link java.util.regex.Matcher#quoteReplacement} to suppress the special
* meaning of these characters, if desired.
*
* @param regex
* the regular expression to which this string is to be matched
*
* @return The resulting {@code String}
*
* if the regular expression's syntax is invalid
*
* @see java.util.regex.Pattern
*
* @since 1.4
*/
< /code>
И нет никаких других конфигураций, кроме конфигураций по умолчанию, которые вы получаете при свежей установке издания сообщества Intelij Idea или недавно созданный проект Maven. он не добавил выделение параметра. < /p>
ожидаемый результат ([] и - подчеркивается из -за того, что он является частью синтаксиса REGEX):
фрагмент кода, который считывает «StringExample0123» .replaceall ("[0-9]", "); Цвет): < /p>
фрагмент кода, который читает Custommethod ("[0-9]"); < /p>
Дополнительное примечание: если ее Intelij Идея зависит от идеи, я использую идею и буду работать только локально, его позор, но его полезно. Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/797 ... er-in-java