오늘밤너를
170
2018-04-16 20:35:42
8
1129

javascript img src 추출 정규식 질문입니다.


src=\"data:image/jpeg;base64,/9j/4RumRXhpZgAASUkqAAgAAAATAAABAwABAAAASA0AAAEBAwABAAAA7BMAAAIBAwADAAAA8gAAAAMBAwABAAAAAQAAAAYBAwABAAAAAgAAAA8BAgASAAAA+AAAABABAgAKAAAACgEAABIBAwABAAAAAQAAABUBAwABAAAAAwAAABoBBQABAAAAFAEAABsBBQABAAAAHAEAABw691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3X/2Q==\" alt="" style="~~~~"

이런 String이 있다고 할때

어떻게 저src값만 추출할까요?

0
0
  • 답변 8

  • aspirins
    108
    2018-04-16 20:37:54

    indexOf로 alt 위치 구하고 substring으로 자르면 되지 않을까요

    0
  • 오늘밤너를
    170
    2018-04-16 20:40:50

    이게 데이터 길이가 가변적이라 그렇게 하면 안될듯요 ㅜㅜ

    0
  • 재민
    545
    2018-04-16 20:56:03

    .getAttribute('src')

    로 하면 되지 않을가여

    0
  • 오늘밤너를
    170
    2018-04-16 21:01:28

    그냥 일반 string이라서 getAttribute 안먹힐듯요 ㅜㅜ

    0
  • Chaed
    1k
    2018-04-16 21:02:25

    우선 src=\".*"으로 추출된 문자열에서 다시 ".*" 로 하면 되지 않을까요?

    0
  • NoDe
    2k
    2018-04-16 21:46:54

    시작에 \ 와 끝에 \ 가 다른 경우에도 존재하나요

    0
  • 북삼촌사람
    756
    2018-04-17 01:51:21 작성 2018-04-17 01:52:31 수정됨


    var str = `src=\"data:image/jpeg;base64,/9j/4RumRXhpZgAASUkqAAgAAAATAAABAwABAAAASA0AAAEBAwABAAAA7BMAAAIBAwADAAAA8gAAAAMBAwABAAAAAQAAAAYBAwABAAAAAgAAAA8BAgASAAAA+AAAABABAgAKAAAACgEAABIBAwABAAAAAQAAABUBAwABAAAAAwAAABoBBQABAAAAFAEAABsBBQABAAAAHAEAABw691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3X/2Q==\" alt="" style="~~~~"`,
      index = str.indexOf('=\"') + 2,
      last = str.lastIndexOf('==') + 2;
    console.log(str.slice(index, last));

    위처럼 해결하면 되지 않을 까요 ? 


    0
  • 초코쪼꼬
    6k
    2018-04-17 08:07:54

    var str = 'src="data:image/jpeg;base64,/9j/4RumRXhpZgAASUkqAAgAAAATAAABAwABAAAASA0AAAEBAwABAAAA7BMAAAIBAwADAAAA8gAAAAMBAwABAAAAAQAAAAYBAwABAAAAAgAAAA8BAgASAAAA+AAAABABAgAKAAAACgEAABIBAwABAAAAAQAAABUBAwABAAAAAwAAABoBBQABAAAAFAEAABsBBQABAAAAHAEAABw691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3X/2Q==" alt="" style="~~~~"';


    str.match(/(src.*)(?=\salt)/g); // ["src="data:image/jpeg;base64,/9j/4RumRXhpZgAASUkqAA…691737r3Xvfuvde9+691737r3Xvfuvde9+691737r3X/2Q==""]

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.