& => &로 바꾸기 정규치환식 질문.

lacovnk의 이미지

그냥 & => &로 하니, & 가 되버려는 현상이 있습니다;

&가 &로 바뀌는 문제 at 태터툴즈

정규치환식에서는 불가능한건가요? 흑.. &(amp;){0} 하니 안되는 것 같던데;

저 링크처럼, 뒤에 amp;가 없는지 확인하고 바꿔주는 함수를 짜야하는건가요? ㅎㅎ

익명 사용자의 이미지

perl -e '$ss="&";$ss=~s/&/&/g;print $ss."\n";'

익명 사용자의 이미지

어째서 html entities 처리를 해주는지 찾아보시기 바랍니다.

익명 사용자의 이미지

뒤에 amp;가 있는지 없는지 확인해서 바꿔주는 정규표현식 만드는것은 간단합니다. (PHP 버젼)

$str = "adfjk & & abcde";
$str = preg_replace("/(&)|&/e", "\"\\1\" ? \"\\1\" : '&'", $str);

다만 < > 라던가 보통 언제 html entity들을 escape시키는가... 혹은 다시 unescape시키면 어떻게 될 것인가를 생각해 볼 때 어설프게 임시방편으로 만들었다간 데이터가 뒤죽박죽 꼬여버립니다.

결론은, 제작자에게 버그를 신고하시길 바랍니다. -_-;

송효진의 이미지

펄 스타일 정규식에서는 특정 문자열이 포함되거나 제외되는것을 실제 정규식 문자열에 포함시키지 않고, 조건만 지정할 수 있습니다.

http://kr.php.net/manual/en/reference.pcre.pattern.syntax.php
http://kr.php.net/manual/en/reference.pcre.pattern.modifiers.php

여기에 펄 스타일 정규식이 잘 나와 있습니다.

그리고, 지금 문제의 요는 &.*; 를 제외하면 되는거죠.

perl -pi -e 's/&(?![a-z0-9]+;)/&/gi' test.txt

futari의 이미지

음..

그냥 editor에 넘겨줄때 "&" 같은걸 원래대로 한번 치환해주면 되는거 아닐까요?

-------------------------
The universe is run by the complex interweaving of three elements: matter, energy, and enlightened self-interest.
- G'kar, Babylon 5

cdpark의 이미지

futari wrote:
그냥 editor에 넘겨줄때 "&" 같은걸 원래대로 한번 치환해주면 되는거 아닐까요?

내부에 저장할 때 사용자가 입력한 그대로를 저장하고, 화면에 뿌려줄 때 &를 &로 바꾸는게 답일 듯 싶네요.

사용자의 입력을 수정할 일이 있다면 원래 내용을 보존해놓고 있는게 가장 깔끔합니다.

mr.lee의 이미지

&(?!amp)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.