정규식 질문입니다.
2011.03.10 15:06
정규식질문입니다. php에서, 텍스트 내의 태그를 걸러내려합니다.
태그 형식은 [key"value"] 인데요, (키값 좌우 여백있을 수 있음) 이를 하나씩 걸러내는 것은 문제가 아닌데
중요한 것은 태그간들간의 무작위적인 텍스트를 순서대로 추출해야 하는 것이 문제입니다.
물론 좀더 복잡하게는 가능하지만 정규식으로 한방에 끝내고 싶다는 생각이어서...
아무튼 예를 들어
/.*\[ *[a-z]* *\"(.*)\"\]/m 으로 맷칭하면
다음과 같이 최후의 것까지 맷칭됩니다.
asdfasdf asdf [this is not a match]as[[[dfaf[
asdf[ event"tournament"]asdfasdfsafas sadfasdfasdfasdf
asdfasdf [ test"this is test"] asdfasfasd fasdf
원하는 맷칭은 이렇습니다.
asdfasdf asdf [this is not a match]as[[[dfaf[
asdf[ event"tournament"]asdfasdfsafas sadfasdfasdfasdf
asdfasdf [ test"this is test"] asdfasfasd fasdf
정규식 잘쓰시는 분들 도와주세요.
음 풀었습니다.
/.+?\[ *[a-z]* *\"(.*)\"\]/m 로 되는군요.