이 ν¬μŠ€νŒ…μ€ 쿠팑 νŒŒνŠΈλ„ˆμŠ€ ν™œλ™μ˜ μΌν™˜μœΌλ‘œ, 이에 λ”°λ₯Έ μΌμ •μ•‘μ˜ 수수료λ₯Ό μ œκ³΅λ°›μ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

λ°˜μ‘ν˜•

import java.util.UUID;
import java.util.Vector;
import java.util.regex.*;

class regexSample
{
 public static void main(String args[])
 {

  Vector<String> vecUUIDs = new Vector<String>();

  for(int i = 0 ; i < 1000 ; i++)
   vecUUIDs.add(UUID.randomUUID().toString());

  System.out.println(UUID.randomUUID());
  //Set the email pattern string
  Pattern p
  =
  Pattern.compile("\\p{Alnum}{8}-\\p{Alnum}{4}-\\p{Alnum}{4}-\\p{Alnum}{4}-\\p{Alnum}{12}");

  //Match the given string with the pattern
  for(int i = 0 ; i < vecUUIDs.size(); i++)
  {
   Matcher m = p.matcher(vecUUIDs.get(i));
   boolean matchFound = m.matches();

   //check whether match is found

   if (matchFound)
    System.out.println(vecUUIDs.get(i)+ " - Valid !.");
   else
    System.out.println(vecUUIDs.get(i)+ "- Invalid !.");
  }
 }
}






Reference : http://www.java2go.net/java/java_regex.html


Reference2 :

μžλ°” μ •κ·œν‘œν˜„μ‹μ—μ„œ \ (μ—­μŠ¬λž˜μ‹œ) ν‘œκΈ°ν•˜κΈ°.

μžλ°” μ •κ·œν‘œν˜„μ‹μ€ μ„±λŠ₯은 μ–΄μ¨Œλ“  νŽ„ ν˜Έν™˜λ˜λŠ” κ½€λ‚˜ μ“Έλ§Œν•œ μ •κ·œν‘œν˜„μ‹μ„ μ œκ³΅ν•œλ‹€. 

그런데 ν•œκ°€μ§€ μ£Όμ˜ν• μ μ€ μžλ°” 슀트링과 μ •κ·œν‘œν˜„μ‹μŠ€νŠΈλ§μ€ μ„œλ‘œ λ‹€λ₯Έ 뢀뢄이 λ§Žλ‹€λŠ” 것이닀. 

λŒ€ν‘œμ μΈκ²ƒμ΄ \ 의 ν‘œκΈ°λ²•μ΄λ‹€. 

μžλ°” μŠ€νŠΈλ§μ—μ„œ \λ₯Ό ν‘œκΈ° ν•˜κΈ° μœ„ν•΄μ„œλŠ” \\ 둜 ν‘œν˜„ν•œλ‹€ 

A \ B  => "A \\ B" 

String src = "A \\ B";

ν•˜μ§€λ§Œ μžλ°”μ •κ·œν‘œν˜„μ‹μ—μ„œλŠ” μ’€ λ‹€λ₯΄λ‹€. μ΄κ²ƒλ•Œλ¬Έμ— κ³ μƒν•˜λŠ” κ²½μš°κ°€ λ§ŽκΈ°λ„ ν•œλ°,
 μžλ°” μ •κ·œν‘œν˜„μ‹μ—μ„œ \ λ₯Ό λ‚˜νƒ€λ‚΄λŠ” 것은 \\\\ 이닀. 4개의 \ λ₯Ό 연이어 써주어야 ν•œλ‹€. 

A \ B => "A \\\\ B" 

Pattern p = Pattern.compile("A \\\\ B");

λ‹¨μˆœνžˆ μ—¬κΈ°μ„œ λλ‚˜λ©΄ 쒋은데 String에 μžˆλŠ” μ—¬λŸ¬ λ©”μ†Œλ“œλ“€μ΄ μž…λ ₯κ°’μœΌλ‘œ μ •κ·œν‘œν˜„μŠ€νŠΈλ§μ„ λ°›μ•„λ“€μ΄λŠ” λΆ€λΆ„μ—μ„œ 버그가 많이 λ°œμƒν•œλ‹€. 

String src = "A \\ B \\ C".replaceAll("\\\\"," or");  
assert "A or B or C".equals(src)

μ΄λ ‡κ²Œ String.replaceAllλ“±μ˜ λ©”μ†Œλ“œλŠ” μ •κ·œν‘œν˜„μ‹ μŠ€νŠΈλ§μ„ λ°›μ•„λ“€μΈλ‹€λŠ”κ²ƒμ„ μœ μ˜ν•΄μ•Ό ν•œλ‹€. 

가끔 μ •κ·œν‘œν˜„μ‹μ„ λ§Œλ“€λ‹€κ°€ 이걸 κΉŒλ¨Ήμ–΄μ„œ κ³ μƒν•˜λŠ” κ²½μš°κ°€ λ§Žμ•„μ„œ 정리해 λ³΄μ•˜λ‹€. 
λ°˜μ‘ν˜•

+ Recent posts