jsup.GEN - working on image-to-image generation with AI

Image
by joviansummer original STEEMIT post: https://steemit.com/blog/@joviansummer/jsup-gen-working-on-image-to-image-generation-with-ai Hello, this is @joviansummer(witness: @jswit). I'd like to share what I'm working on regarding my experintal jsup.GEN project, which tries to connect image generation AI with Steemit. Currently, jsup.GEN provide function to generate image from test prompt(txt2img). This function is interesting, but it's not easy to generate exactly what you want because you need to explain the image in detail with multiple keywords in English. Thus, I think it's more useful to have a function to generate image from existing reference image. I'm working on this image-to-image function, and thinking about two methods to implement it. The first method is to provide 2 commands as follows: !gen_t : This command focuses more on text prompt than reference image. The result may be quite different from reference because text prompt will have much more in...

파이썬에서 정규표현식(regex)을 이용한 문자열 검색

by joviansummer
original STEEMIT post: https://steemit.com/blog/@joviansummer/regex


파이썬에서 정규표현식(regular expression)을 이용해서 검색 조건에 일치하는 문자열인지 확인하는 방법입니다.

예시를 보겠습니다. 문자열 'abc', 'def', '123', '1abc' 이렇게 4개를 묶어 리스트(list)로 만들고 영문 소문자([a-z])를 검색해 봅니다.

import re

# 리스트 생성
str_list = ['abc', 'def', '123', '1abc']

# 적용할 정규표현식을 컴파일하여 regex에 할당
regex = re.compile('[a-z]')

이제 for 반목문으로 str_list에 속한 문자열들에 대해서 검색을 합니다. 우선 match()를 사용해 봅니다.

for i in str_list:
  if regex.match(i):
    print(i)

abc def

match()는 문자열 처음부터 조건과 일치하는지 검색합니다. 위의 예시에서는 문자열 'abc'와 'def'가 처음부터 영문 소문자로 시작하므로 조건에 부합하여 줄력되었습니다.

search()는 문자열 전체에 대해 일치하는 부분이 있는지를 검색합니다.

for i in str_list:
  if regex.search(i):
    print(i)

abc def 1abc

문자열 '1abc'의 경우 영문 소문자로 시작하지 않기 때문에 match()에서는 조건에 부합하지 않지만, 영문 소문자를 포함하고 있으므로 search()에서는 조건에 부합되어 출력됩니다.

findall()은 조건에 맞는 문자열을 모두 찾아서 리스트 형태로 가져옵니다.

x = 'hello'
y = regex.findall(x)
print(y)

['h', 'e', 'l', 'l', 'o']

문장으로부터 영문 소문자 단어를 분리하려면 아래와 같이 해 볼 수 있겠습니다.

# 영문 소문자가 1번 이상 반복: 정규표현식 [a-z]+
regex2 = re.compile('[a-z]+')
x = 'my name is joviansummer.'
y = regex2.findall(x)
print(y)

['my', 'name', 'is', 'joviansummer']

Comments

Popular posts from this blog

스티미언의 영향력 지수 계산

jsup/avle code update - you don't have to write post everyday

jsup/avle 보팅 코드 갱신 - 1일1포스팅 강박에서 벗어나기