Regular expression

Computer/Terms 2007. 12. 20. 20:37

In computing, a regular expression is a string that is used to describe or match a set of strings, according to certain syntax rules.

Regular expressions are used by many text editors, utilities, and programming languages to search and manipulate text based on patterns. For example, Perl and Tcl have a powerful regular expression engine built directly into their syntax. Several utilities provided by Unix distributions—including the editor ed and the filter grep—were the first to popularize the concept of regular expressions. "Regular expression" is often shortened to regex or regexp (singular), or regexes, regexps, or regexen (plural). Some authors distinguish between regular expression and abbreviated forms such as regex, restricting the former to true regular expressions, which describe regular languages, while using the latter for any regular expression-like pattern, including those that describe languages that are not regular. As only some authors observe this distinction, it is not safe to rely upon it.

As an example of the syntax, the regular expression \bex can be used to search for all instances of the string "ex" that occur at word boundaries (signified by the \b). Thus in the string, "Texts for experts," \bex matches the "ex" in "experts," but not in "Texts" (because the "ex" occurs inside the word there and not immediately after a word boundary).

Many modern computing systems provide wildcard characters in matching filenames from a file system. This is a core capability of many command-line shells and is also known as globbing. Wildcards differ from regular expressions in that they generally only express very restrictive forms of alternation.


Reference;
http://en.wikipedia.org/wiki/Regular_expression

Posted by 알 수 없는 사용자
,

자바에서는 객체의 각 필드에 직접 접근하기보다는

get/set 메소드를 통해서 접근한다.

하지만 get/set 메소드를 직접 만드는 일은 필드의 수가 많으면

비효율적일 수 밖에 없다.

이클립스에서는 이를 자동화할 수 있는 기능을 제공한다.

먼저, 원하는 필드를 블럭으로 지정하고,

마우스 오른쪽 버튼을 누른다.

Source -> Generate Getters and Setters

원하는 세부 설정을 한 뒤에 OK 버튼을 누르면 끝!
Posted by 알 수 없는 사용자
,

다음은 vsms라는 데이터베이스 내에 test라는 테이블에 한글 데이터를 넣는 예제 프로그램이다.

import java.sql.*;

public class MySQLKoreanInsertDemo {
 public static void main(String[] args) {
  try {
   Class.forName("com.mysql.jdbc.Driver").newInstance();
  } catch (ClassNotFoundException e) {
   System.err.println(e);
  } catch (InstantiationException e) {
   System.err.println(e);
  } catch (IllegalAccessException e) {
   System.err.println(e);
  }

  String server = "localhost";
  String dbname = "vsms";
  String username = "user1";
  String password = "passwd1";

  String url = "jdbc:mysql://" + server + "/" + dbname
    + "?user=" + username
    + "&password=" + password
    + "&useUnicode=true&characterEncoding=euc_kr";

  try {
   Connection conn = DriverManager.getConnection(url);
   Statement stmt = conn.createStatement();

   String query = "INSERT INTO test (data) VALUES ('임정묵')";

   stmt.executeUpdate(query);

   stmt.close();
   conn.close();
  } catch (SQLException e) {
   System.err.println(e);
  }
 }
}


위에서 "&useUnicode=true&characterEncoding=euc_kr"가 필요함에 유의한다.

Posted by 알 수 없는 사용자
,