public:computer:regexp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revisionBoth sides next revision
public:computer:regexp [2021/12/23 14:26] – [자주 쓰는 정규표현식] alexpublic:computer:regexp [2023/01/01 00:56] – [참조 그룹] alex
Line 70: Line 70:
  
 ==== 참조 그룹 ==== ==== 참조 그룹 ====
-  * 찾고자 하는 내용을 ()로 감싼 후(참조) $1, $2 혹은 \1, \2와 같이 역참조+  * 찾고자 하는 내용을 ()로 감싼 후(참조) \$1, \$2 혹은 \1, \2와 같이 역참조
  
  
Line 260: Line 260:
   * 숫자만으로만 되어있는지 확인; <alert type="info"><nowiki>(JAVA) bDigitsOnly = str.matches("^\\d+\$");</nowiki></alert>   * 숫자만으로만 되어있는지 확인; <alert type="info"><nowiki>(JAVA) bDigitsOnly = str.matches("^\\d+\$");</nowiki></alert>
   * 첫글자만 보이게 마스킹; <alert type="info"><nowiki>(JAVA) strMasked = str.replaceFirst("(^\\S)\\S+\$", "\$1*****");</nowiki></alert>   * 첫글자만 보이게 마스킹; <alert type="info"><nowiki>(JAVA) strMasked = str.replaceFirst("(^\\S)\\S+\$", "\$1*****");</nowiki></alert>
 +  * Password Validataions (JAVA & TypeScript)<sxh java title:Password Validation for JAVA>
 +
 +    public static Boolean hasSpecialCharacter(String strPassword) 
 +    {
 +        Boolean bHasSpecialCharacter = Pattern.matches("^(?=.*[\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]).{1,}", strPassword);
 +
 +        if(true == bHasSpecialCharacter)
 +        {
 +            System.out.println(strPassword + " has Special Character.");
 +        }
 +        else
 +        {
 +            System.out.println(strPassword + " has no Special Character.");
 +        }
 +
 +        return bHasSpecialCharacter;
 +    }
 +
 +    public static Boolean isValidPassword(String strPassword) 
 +    {
 +        Boolean bValid = Pattern.matches("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\\x21-\\x2f|\\x3a-\\x40|\\x5b-\\x60|\\x7b-\\x7e]).{10,16}", strPassword);
 +
 +        System.out.println(strPassword + ":" + bValid);
 +        return bValid;
 +    }
 +
 +    public static Boolean hasAlphabet(String strPassword) 
 +    {
 +        Boolean bHasAlphabet = Pattern.matches("^(?=.*[a-zA-Z]).{1,}", strPassword);
 +
 +        if(true == bHasAlphabet) 
 +        {
 +            System.out.println(strPassword + " has Alphabet.");
 +        }
 +        else
 +        {
 +            System.out.println(strPassword + " has no Alphabet.");
 +        }
 +
 +        return bHasAlphabet;
 +    }
 +
 +    public static Boolean hasDigit(String strPassword)
 +    {
 +        Boolean bHasDigit = Pattern.matches("^(?=.*[\\d]).{1,}", strPassword);
 +
 +        if(true == bHasDigit)
 +        {
 +            System.out.println(strPassword + " has Digits.");
 +        }
 +        else
 +        {
 +            System.out.println(strPassword + " has no Digits.");
 +        }
 +
 +        return bHasDigit;
 +    }
 +
 +    public static void testPassword(String strPassword)
 +    {
 +        System.out.println("Your password is : " + strPassword);
 +
 +        hasAlphabet(strPassword);
 +        hasDigit(strPassword);
 +        hasSpecialCharacter(strPassword);
 +    }</sxh><sxh typescript title:Password Validation for TypeScript>
 +function hasAlphabet(strPassword: string) {
 +  const reg = new RegExp("^(?=.*[a-zA-Z]).{1,}$")
 +  const bHasAlphabet = reg.test(strPassword)
 +
 +  if(false === bHasAlphabet) {
 +    console.log(`${strPassword} has no alphabet.`)
 +  } else {
 +    console.log(`${strPassword} has alphabet.`)
 +  }
 +    
 +  return bHasAlphabet
 +}
 +
 +function hasDigit(strPassword: string) {
 +  const reg = new RegExp("^(?=.*[0-9]).{1,}$")
 +  const bHasDigit = reg.test(strPassword)
 +
 +  if(false === bHasDigit) {
 +    console.log(`${strPassword} has no digit.`)
 +  } else {
 +    console.log(`${strPassword} has digit.`)
 +  }
 +
 +  return bHasDigit
 +}
 +
 +function hasSpecialCharacter(strPassword: string) {
 +  const reg = new RegExp("^(?=.*[\\x21-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\x7e]).{1,}$")
 +  const bHasSpecialCharacter = reg.test(strPassword)
 +
 +  if(false === bHasSpecialCharacter){
 +    console.log(`${strPassword} has no special character.`)
 +  } else {
 +    console.log(`${strPassword} has special character.`)
 +  }
 +
 +  return bHasSpecialCharacter
 +}
 +
 +function isValidPassword(strPassword: string) {
 +  const reg = new RegExp("^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\\x21-\\x2f|\\x3a-\\x40|\\x5b-\\x60|\\x7b-\\x7e]).{10,16}$")
 +  const bValid = reg.test(strPassword)
 +
 +  if(false === bValid) {
 +    console.log(`${strPassword} is invalid.`)
 +  } else {
 +    console.log(`${strPassword} is valid.`)
 +  }
 +
 +  return bValid
 +}
 +
 +function testPassword(strPassword: string) {
 +  console.log(`Your Password is : ${strPassword}`)
 +
 +  hasAlphabet(strPassword)
 +  hasDigit(strPassword)
 +  hasSpecialCharacter(strPassword)
 +
 +  isValidPassword(strPassword)
 +
 +}</sxh>
 +  * camelCase to snake_case and MACRO_CASE (JAVA)<sxh java title:camelCase to snake_case and MACRO_CASE for JAVA>
 +    public static String getSnakeCaseFromCamelCase(String strCamelCase)
 +    {
 +        return strCamelCase.replaceAll("([A-Z])", "_$1").toLowerCase();
 +    }
 +
 +    public static String getMacroCaseFromCamelCase(String strCamelCase) 
 +    {
 +        return strCamelCase.replaceAll("([A-Z])", "_$1").toUpperCase();
 +    }
 +</sxh>
 +  * Card Number Validation (TypeScript)<sxh typescript title:Card Number Validation Example for TypeScript>
 +function validateIBKCEOCard(strCardNumber: string) {
 +  const regDigitsOnly = /(\D+)/gi
 +  const strDigits = strCardNumber.replace(regDigitsOnly, "")
 +
 +  if (strDigits.length != 16) {
 +    console.log(strCardNumber + ' is invalid card number')
 +    return
 +  }
 +  
 +  console.log('validate IBK CEO Card: ' + strCardNumber + ' => ' + strDigits + '(' + strDigits.length + ')')
 +
 +  const regValidate: RegExp = /^943003|^552103\d+$/g
 +  const bValid = regValidate.test(strDigits)
 +
 +  console.log('is valid? ' + bValid)
 +}
 +</sxh>
  
  
Line 276: Line 433:
   * [[https://www.regexpal.com/|RegEx Pal]]   * [[https://www.regexpal.com/|RegEx Pal]]
   * [[https://regexr.com/|RegExr]]   * [[https://regexr.com/|RegExr]]
-  * rubular+  * [[https://rubular.com/|Rubular]]
  
  
Line 299: Line 456:
   * [[https://intro0517.tistory.com/135|자바스크립트 정규식 정리(숫자만, 한글만, 메일, 전화번호, 비밀번호)]]   * [[https://intro0517.tistory.com/135|자바스크립트 정규식 정리(숫자만, 한글만, 메일, 전화번호, 비밀번호)]]
   * [[https://develop-sense.tistory.com/62|[JAVA] 정규식을 이용한 마스킹(정규표현식 마스킹 처리)]]   * [[https://develop-sense.tistory.com/62|[JAVA] 정규식을 이용한 마스킹(정규표현식 마스킹 처리)]]
 +  * [[https://leejiheg.tistory.com/entry/%EC%A0%95%EA%B7%9C-%ED%91%9C%ED%98%84%EC%8B%9D-%EA%B8%B0%EB%B3%B8|정규 표현식 기본]]
 +  * [[https://youngjinmo.github.io/2020/01/reg/|정규표현식(Reg)]]
 +  * [[https://minj0i.tistory.com/26|[JAVA] 이름 마스킹처리]]
 +  * [[https://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html|Class Pattern]]
 +  * [[https://blog.naver.com/PostView.nhn?blogId=realuv&logNo=220699272999|[Javascript] 정규식을 이용한 특수문자, 한글 등 특정 문자 체크(제거)]]
 +
 +
  
  
  
  
  • public/computer/regexp.txt
  • Last modified: 2023/01/01 00:58
  • by alex