자바 정규식 - 출처 sun java tutorial

public class RegexTestHarness {

    public static void main(String[] args){
        java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("foo"); //검색할 문자열
  java.util.regex.Matcher matcher = pattern.matcher("fool");                //대상문자열

  boolean found = false;
  while (matcher.find()) {
   System.out.println(matcher.group());
   System.out.println(matcher.start());
   System.out.println(matcher.end());
   found = true;
  }
  if(!found){
   System.out.println("No match found.%n");
        }
    }
}

by 엘시스라아르위르 | 2008/10/08 17:34 | 트랙백 | 덧글(0)
메소드 알아내기..

import java.util.*;
import java.lang.reflect.*;

public class testGetMethod {
 public static void main(String[] args) {
  testGetMethod tm = new testGetMethod();
  tm.identifyMethod("insert");
 }

 public void identifyMethod(String str) {
  Class[] param = {HashMap.class};

  Method m = null;
  try {
   m = this.getClass().getDeclaredMethod(str,param);
  } catch (NoSuchMethodException nsme) {
  }

  Object oc = null;
  try {
   oc = this.getClass().newInstance();
  } catch (InstantiationException ie) {
  } catch (IllegalAccessException ile) {
  }
  
  
  HashMap[] hm = {new HashMap()};
  try {
   m.invoke(oc,hm);
  } catch (IllegalAccessException iae){
  } catch (InvocationTargetException ite) {
  }
 }

 public void insert(HashMap map) {
  System.out.println("definitely insert called...");
 }
}

by 엘시스라아르위르 | 2008/07/03 16:21 | Thinking In Java SE5 | 트랙백 | 덧글(0)
body disabled

document.body.disabled = true;

프레임 있는 경우 parent.fn명/프레임.fn명

## 프레임을 이용한 submit(부모창의 프레임 Name)
parent.hidfrm1.frm.target= "Frame1";//parent.body.name;
parent.hidfrm1.frm.action= "dummy.jsp";
parent.hidfrm1.frm.submit();

## 프레임 이용한 submit
hidfrm1.frm.target= "Frame1";//parent.body.name;
hidfrm1.frm.action= "dummy.jsp";
hidfrm1.frm.submit();

by 엘시스라아르위르 | 2008/03/19 13:43 | script | 트랙백 | 덧글(0)
파이썬..특정 이미지 경로 추출 후 중복제거

내 python 첫번째 프로그램(아래 거가 첫번짼가?? 암튼..그나마 정상적으로 보이는 것으로 첫번째)

# -*- coding: cp949 -*-

## grep으로 뽑아온 목록에서 img 만 추출해냄..
j = file('wbcus900_01t6.jsp')
o = file('list.txt','w')
line = j.readline()
print 'start1...'
while line :
    flag1 = line.find('/img')
    if flag1 != -1 :
        a = line.index('/img')
        flag2 = line.find('.gif')
        flag3 = line.find('.jpg')
        if flag2 != -1 :
            b = line.index('.gif') + 4
        elif flag3 != -1 :
            b = line.index('.jpg') + 4
        #print line[a : b]
        o.write(line[a : b] + '\n')
    line = j.readline()
j.close()
o.close()
print 'end start1...'

## img만 추출한 목록에서 중복된 부분 제외
f = file('list.txt')
t = file('img_list.txt','w')

line = f.readline().strip() # 공백을 없애자.. 크흑..
list = [] #중복되지 않은값을 넣는 리스트
print 'start2...'

while line :
    cnt = 0

    # 중복여부 체크
    for attr in list :
        if line == attr :
            cnt = cnt + 1

    if cnt == 0 :
        list.append(line)
        t.write(line + '\n')
       
    line = f.readline().strip()

   
f.close()
t.close()

print 'end start2...'

by 엘시스라아르위르 | 2008/03/02 15:02 | script | 트랙백 | 덧글(0)
첫 파이썬..프로그램 --; 허섭 그 자체

f = file('d:\\f.txt')
line = f.readline()
while line :
 print line.strip()
 line = f.readline()
 
 
f = open('tt.txt','w')
f.write('222\n')
f.close()

s = "i like programming.'
s.index('like') ==> 2 (s.find('like') 후에 검색)


s.startswith('i like')
s.endswith('swimming')
s.strip() ==> 공백제거

 

f = file('tt.txt')
line = f.readline()
while line:
 a = line.find('/img')
 if a != -1 :
  b = line.index('/img')
  print line
 line = f.readline()


s = ''
>>> f = file('tt.txt')
>>> line = f.readline()
>>> while line :
 a = line.find('/img')
 if a != -1 :
  s = s + line
 line = f.readline()
 print s
 
 
 f = file('tt.txt')
>>> for line in f :
 print line


s = '<img = /img/img.gif>'
>>> s[s.index('.gif') : s.index('.gif') + 4]
'.gif'

 

 

=====================

f = file('wbcus900_01t6.jsp')
line = f.readline()
while line :
 flag1 = line.find('/img')
 if flag1 != -1 :
  a = line.index('/img')
  flag2 = line.find('.gif')
  flag3 = line.find('.jpg')
  if flag2 != -1 :
   b = line.index('.gif') + 4
  elif flag3 != -1 :
   b = line.index('.jpg') + 4
  print line[a : b]
 line = f.readline()
 
 
---------

f = file('wbcus900_01t6.jsp')
 o = file('o.txt','w')
 line = f.readline()
 while line :
 flag1 = line.find('/img')
 if flag1 != -1 :
  a = line.index('/img')
  flag2 = line.find('.gif')
  flag3 = line.find('.jpg')
  if flag2 != -1 :
   b = line.index('.gif') + 4
  elif flag3 != -1 :
   b = line.index('.jpg') + 4
  print line[a : b]
  o.write(line[a : b])
 line = f.readline()

by 엘시스라아르위르 | 2008/03/01 03:33 | script | 트랙백 | 덧글(0)
끄적
var sep = (__logout_server.split('.'))[0]; // http://www 와 .도메인.com 를 분리
var biz_yn   = sep.search('biz');
var index_uri;
by 엘시스라아르위르 | 2008/02/26 21:05 | 트랙백 | 덧글(0)
동적으로 js 파일 추가하는것..
웹에 돌아당기는 거... 원본은 어딘지 기억이.. 하도 여러 사이트에서 동일한 내용이 있어서리..

함 해봤는데..

동기화 문제를 해결 못했슴

또 다시 웹서핑 해봐야징..

var js = 'js';
var script=document.createElement("script");
script.src = "/js/js.js";
document.getElementsByTagName("head")[0].appendChild(script);
by 엘시스라아르위르 | 2008/02/14 23:05 | script | 트랙백 | 덧글(0)
클래스 메소드 알아내기..

page 536

import java.lang.reflect.*;
import java.util.regex.*;

public class ShowMethods {
 private static String usage =
  "usage:\n" +
  "ShowMethods qualified.class.name\n" +
  "To show all methods in class or:\n" +
  "ShowMethods qualified.class.name word\n" +
  "To search for methods involving 'word'";
 private static Pattern p = Pattern.compile("\\w+\\.");
 public static void main(String[] args) {
  if(args.length < 1) {
   System.out.println(usage);
   System.exit(0);
  }
  int lines = 0;
  
  try {
   Class<?> c = Class.forName(args[0]);
   Method[] methods = c.getMethods();
   Constructor[] ctors = c.getConstructors();
   if(args.length == 1) {
    for(Method method : methods)
     System.out.println(p.matcher(method.toString()).replaceAll(""));
    lines = methods.length + ctors.length;
   } else {
    for(Method method : methods)
     if(method.toString().indexOf(args[1]) != -1) {
      System.out.println(p.matcher(method.toString()).replaceAll(""));
      lines++;
     }
    for(Constructor ctor : ctors)
     if(ctor.toString().indexOf(args[1]) != -1) {
      System.out.println(p.matcher(ctor.toString()).replaceAll(""));
      lines++;
     }
   }
  } catch (ClassNotFoundException e) {
   System.out.println("No such class: " + e);
  }
 }
}

by 엘시스라아르위르 | 2008/02/11 01:06 | Thinking In Java SE5 | 트랙백 | 덧글(0)
끄적

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script language="javascript">
<!--
 Tune = function(title) {
  this.title = "world";
  var performedBy = new Array();
  
  this.addPerformer = function(performer) {
   var i = performedBy.length;
   performedBy[i] = performer;
  }
  this.listPerformers = function() {
   var singers = "";
   for(var i = 0; i < performedBy.length; i++) {
    singers += performedBy[i] + " ";
   }
   alert(singers);
  }
  this.getTitle = function() {
   return this.title;
  }
 }

 function go() {
  var song = new Tune("Hello");
  song.addPerformer("Me");
  song.addPerformer("You");
  song.addPerformer("Us");
  song.listPerformers();
  alert('해보자');
  alert(song.getTitle());
 }
//-->
</script>
</HEAD>

<BODY>
<input type="button" value="go" onClick="go();">
</BODY>
</HTML>


================================================

<html>
<head>
<script type="text/javascript">
 function whichElement(e)
 {
  var targ;
  if (!e) {
   alert('1');
   var e=window.event;
  }

  if (e.target) {
   alert('2');
   targ=e.target;
  } else if (e.srcElement) {
   alert('3');
   targ=e.srcElement;
  }

  if (targ.nodeType==3) {// defeat Safari bug
   alert('4');
   targ = targ.parentNode;
  }

  var tname=targ.tagName;
  alert("You clicked on a " + tname + " element.");
 }
</script>
</head>

<body onmousedown="whichElement(event)">
<p>Click somewhere in the document. An alert box will alert the tag name of the element you clicked on.</p>

<h3>This is a header</h3>
<p>This is a paragraph</p>
<img border="0" src="ball16.gif" width="29" height="28" alt="Ball">
</body>
</html>

=================

//////////////////////////////////////////////////////////////////
     
     /*
     Iterator iter = hmAcctInfo.keySet().iterator();
     Iterator inter = null;
     int i = 0;
     while(iter.hasNext()){
      
      System.out.println(i+"번째 값 ==> "+iter.next());
      i++;
     }
     */
     
     Set set1 = hmAcctInfo.keySet();
     Object []hmKeys = set1.toArray();
     Vector v = new Vector();
     
     for(int i = 0; i < hmKeys.length; i++) {
      String key = (String)hmKeys[i];
      System.out.println("==========================");
      System.out.println(key);
      System.out.println(" - ");
      System.out.println((Vector)hmAcctInfo.get(key));
      v = (Vector)hmAcctInfo.get(key);
      
      for(int j = 0,n = v.size(); j < n; j++) {
       String[] str = (String[])v.get(j);
       
       for(int k = 0; k < str.length; k++) {
        System.out.println(str[k]);
       }
      }
      System.out.println("==========================");
     }

     //////////////////////////////////////////////////////////////////

===============================================================================

var acc_id = model.getValue("/root/ret/brFdaccCd");
     
     var node = instance1.selectSingleNode("/root/coDepth/brFdaccCd/brFdaccCd/grade001");
     alert(node.nodeName);
     var nodeList = node.childNodes;
     //for(var i = 0; i < nodeList.length; i++){
     // if(acc_id == nodeList(i).text){
     //  alert(nodeList(i).text);
     // }
     // alert(nodeList(i).nodeValue);
     // alert(nodeList(i).text);
     //}
     var accName = nodeList(0).nodeValue;
     var accNameArr = accName.split(":");
     
     alert(accNameArr[0]);
     alert("=="+accNameArr[1]+"==");
     
     if(accNameArr[1] == " 기타의유가증권"){
      alert(accNameArr[1]);
     }
     ////////////////////////////////////////////////////////////////////////////////////////

===============================================================================================

import java.lang.reflect.*;
import java.util.regex.*;
import static net.mindview.util.Print.*;

public class ShowMethods {
 private static String usage = "usage:\n" +
        "ShowMethods qualified.class.name\n" +
        "To show all methods in class or";
 private static Pattern p = Pattern.compile("\\w+\\.");
 public static void main(String[] args){
  if(args.length < 1){
   print(usage);
   System.exit(0);
  }
  int lines = 0;
  
  try{
   Class<?> c = Class.forName(args[0]);
   Method[] methods = c.getMethods();
   Constructor[] ctors = c.getConstructors();
   Class[] cl = null;
   if(args.length == 1){
    for(Method method : methods){
     print("method's name==>"+method.getName());
     
     cl = method.getParameterTypes();
     for(Class cls : cl)
      print("CL==>"+cls);
     print(p.matcher(method.toString()).replaceAll(""));
     print("==============================================");
    }
    
    
    
    
    
    //for(Constructor ctor : ctors)
    // print(p.matcher(ctor.toString()).replaceAll(""));
    //lines = methods.length + ctors.length;
//   } else {
//    for(Method method : methods)
//     if(method.toString().indexOf(args[1]) != -1){
//      print(p.matcher(method.toString()).replaceAll(""));
//      lines++;
//     }
//    for(Constructor ctor : ctors){
//     if(ctor.toString().indexOf(args[1]) != -1){
//      print(p.matcher(ctor.toString()).replaceAll(""));
//      lines++;
//     }
//    }
   }
   
  } catch(ClassNotFoundException e){
   print("No such class: " + e);
  }
 }
}


===============================================================================================

import java.lang.reflect.*;

public class method2 {
 public int add(int a,int b){
  return a+b;
 }
 
 public static void main(String[] args){
  try {
   Class cls = Class.forName("method2");
   Class partypes[] = new Class[2];
   partypes[0] = Integer.TYPE;
   partypes[1] = Integer.TYPE;
   
   Method meth = cls.getMethod("add",partypes);
   method2 methobj = new method2();
   
   Object arglist[] = new Object[2];
   arglist[0] = new Integer(37);
   arglist[1] = new Integer(47);
   
   Object retobj = meth.invoke(methobj,arglist);
   Integer retval = (Integer)retobj;
   
   System.out.println(retval.intValue());
  } catch (Throwable e) {
   System.err.println(e);
  }
 }
}

////////////////////////////////////////////////////////////////////
Class actionClass = this.getClass();
Class[] methodParam = {HttpServletRequest.class,Map.class};
Method method = actionClass.getDeclaredMethod(workType,methodParam);
method.invoke(this,new Object[]{request,parameterMap});
////////////////////////////////////////////////////////////////////


================================================================================

by 엘시스라아르위르 | 2008/01/29 20:39 | script | 트랙백 | 덧글(0)


< 이전페이지 다음페이지 >