Skip to content

Instantly share code, notes, and snippets.

@kosh04
Created December 10, 2010 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kosh04/736787 to your computer and use it in GitHub Desktop.
Save kosh04/736787 to your computer and use it in GitHub Desktop.
[newLISP][PCRE]Perl互換正規表現のサンプル
#!/usr/bin/env newlisp
# change all "foo.bar.com" style names in the input stream
# into "foo.bar.com [204.148.40.9]" (or whatever) instead
# Original Source (perl) - http://docstore.mik.ua/orelly/perl4/cook/ch06_05.htm
# Usage: newlisp hostcvt.lsp < /etc/hosts
(define (echo (in 0) (out 1))
(let (buf)
(while (read in buf 0x400)
(write out buf))
(if (string? out) out true)))
;; Read stdin into string
(setq TEXT (echo 0 ""))
(replace
{ # substitute this:
( # capture the hostname in $1
(?: # these parens for grouping only
(?! [-_] ) # next mustn't be underbar or dash
[\w-] + # one or more alphanums or dashes
\. # and the domain dot
) + # now repeat that whole thing a bunch of times
(?= [a-z] ) # next must be a letter
[\w-] + # one or more alphanums or dashes
) # end of $1 capture
}
TEXT
(format "%s [%s]" $1 (or (net-lookup $1) "???"))
(| 1 8) ; (i)PCRE_CASELESS, (x)PCRE_EXTENDED
)
(print TEXT)
(exit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment