하위 표현식 "[ ]"은 괄호 안에 지정된 모든 문자와 일치합니다. 따라서 모든 대문자를 문자열 끝으로 이동하려면 다음 단계를 수행해야 합니다.
주어진 문자열의 모든 문자를 반복합니다.
주어진 문자열의 모든 대문자를 일치시키려면 "[A-Z]" 정규식을 사용하세요.
특수 문자와 나머지 문자를 두 개의 다른 문자열로 연결합니다.
마지막으로 특수 문자열을 다른 문자열로 연결합니다.
예제 1
public class RemovingSpecialCharacters { public static void main(String args[]) { String input = "sample B text C with G upper case LM characters in between"; String regex = "[A-Z]"; String specialChars = ""; String inputData = ""; for(int i=0; i< input.length(); i++) { char ch = input.charAt(i); if(String.valueOf(ch).matches(regex)) { specialChars = specialChars + ch; } else { inputData = inputData + ch; } } System.out.println("Result: "+inputData+specialChars); } }
Output
Result: sample text with upper case characters in betweenBCGLM
예제 2
다음은 Regex 패키지 방식을 사용하여 대문자를 이동하는 Java 프로그램입니다. 끝까지 문자열.
import java.util.regex.Matcher; import java.util.regex.Pattern; public class Test { public static void main(String args[]) { String input = "sample B text C with G upper case LM characters in between"; String regex = "[A-Z]"; String specialChars = ""; System.out.println("Input string: \n"+input); //Creating a pattern object Pattern pattern = Pattern.compile(regex); //Matching the compiled pattern in the String Matcher matcher = pattern.matcher(input); //Creating an empty string buffer StringBuffer sb = new StringBuffer(); while (matcher.find()) { specialChars = specialChars+matcher.group(); matcher.appendReplacement(sb, ""); } matcher.appendTail(sb); System.out.println("Result: \n"+ sb.toString()+specialChars ); } }
Output
Input string: sample B text C with G upper case LM characters in between Result: sample text with upper case characters in betweenBCGLM
위 내용은 Java 정규식을 사용하여 모든 대문자를 문자열 끝으로 이동의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

Dreamweaver Mac版
시각적 웹 개발 도구

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.
