정규표현식 — 전방탐색, 후방탐색

Lee MunHaeng
Feb 22, 2017 · 1 min read

?= 전방탐색

?<=후방탐색

?! 부정형 전방 탐색

?<! 부정형 후방 탐색

전방,후방 탐색은 탐색된 문자를 결과에 포함하냐 안하냐만 차이가 난다.

예를들어, http://ThisIsTest.com

  • \w+(?=:) 로 매칭하면 http가 매칭
  • \w+(:)로 매칭하면 http:가 매칭

$1.234 $234 It’s 22th Feb. 에서 달러 금액만 찾고자 한다.

  • (?<=\$)[\d.]+로 검색하면 1.234와 234가 매칭된다.

(?<= <[tT][iI][tT][lL][eE]>).*(?=<[tT][iI][tT][lL][eE]>)은 title태그 사이 내용만 매칭된다.

  • <title> this is title </title>

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store