티스토리 뷰

기사 작성하는 웹 툴(집배신)을 만들어서 런칭하였는데
MAC OS9.2 기반 QuarkXpress 3.3으로 신문 제작하는 부서에서 장애 건이 들어왔다.

한글(워드프로세서)에서는 따옴표 입력시 키보드의 해당 키를 누르면
‘문장’ 또는 “문장” 으로 알아서 특수문자 따옴표로 문장의 앞,뒤를 열고 닫아주는데
인터넷은 항상 " 로만 입력되어 교열에서 계속 그것을 바꾸어 주어야하는 문제가 있다고 했다.

하여 웹에디터에 있는 특수문자 입력창을 띄워줄까 생각하다가
정규표현식으로 해결하려 했다.

어허~ 그런데 RegExp.Replace 에 Pattern을 정확히 줘도
문장의 시작과 끝을 정확히 인식하여 변경하여주지 못하였다.
'// 조판을 위한 문장 따옴표 치환 - 이건 안됨! 망할!!
Set regEx = New regEx
With regEx
.Pattern = "'(.*)'"
.Replace "문장", "‘$1’"
End With

참으로 여러가지 삽질을 한 끝에
매칭되는것들을 모두 string Replace 로 바꾸어주는 방식을 택하여 끝장을 봤다.
'// 조판을 위한 문장 따옴표 치환
Function quotes_replace(txt)
	Dim regEx, Match, Matches, strFound, strReplace   ' Create variable.

	Set regEx = New RegExp   ' Create a regular expression.
	With regEx
		.IgnoreCase = True   ' Set case insensitivity.
		.Global = True   ' Set global applicability.

		.Pattern = "'(.|\n)*?'"   ' Set pattern.
		Set Matches = .Execute(txt)   ' Execute search.
		For Each Match in Matches   ' Iterate Matches collection.
			strFound = Match.Value
			strReplace = "‘"& replace(strFound, "'", "") &"’"
			'echo("

"& strFound &"

") ' debug str = str_replace(strFound, strReplace, txt) Next Set Matches = Nothing .Pattern = """(.|\n)*?""" ' Set pattern. Set Matches = .Execute(txt) ' Execute search. For Each Match in Matches ' Iterate Matches collection. strFound = Match.Value strReplace = "“"& replace(strFound, """", "") &"”" 'echo("

"& strFound &"

") ' debug str = str_replace(strFound, strReplace, txt) Next Set Matches = Nothing End With Set regEx = Nothing quotes_replace = txt End Function
댓글