본문 바로가기
IT/Java

정규식 추출

by 봉즙 2020. 3. 17.
package test2;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class main {
	public static void main(String[] args) {

		try {
			String content = "<p><img src=\"/aws/getImg?fileName=123445667878.jpg&amp;directory=boardAttach/2020/03/17/\" style=\"width: 594px;\">\n"
					+ "\n" + "                </p>";
			
			Pattern pattern = Pattern.compile("src=[\"'](.*?)(\")");
	
			Matcher matcher = pattern.matcher(content);


			while (matcher.find()) {
				System.out.println(matcher.group(1));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}

 

<img 같이 태그에서 원하는 부분만 자르기 위한 정규식

'IT > Java' 카테고리의 다른 글

Thread Safe  (0) 2020.07.08
Field Injection | Contructor Injection  (0) 2020.07.07
이펙티브 자바 8장 - 메서드  (0) 2020.01.06
이펙티브 자바 - 7장 람다와 스트림  (0) 2020.01.03
이펙티브 자바 6장 - enum 2  (0) 2020.01.03

댓글