Skip to content

URLs are not matched #15

Open
Open

Description

@lemon234071
text = "郭麒麟打卡,且听他分享防疫小知识https://www.zhihu.com/qution/319823639哈哈http//t.cn/a67ov8bt哈哈哈http://t.c"
cleantext.replace_urls(text, "XXX")

output:

郭麒麟打卡,且听他分享防疫小知识https://www.zhihu.com/qution/319823639哈哈http//t.cn/a67ov8bt哈哈哈哈http://t.c

Expected:

郭麒麟打卡,且听他分享防疫小知识XXX哈哈XXX哈哈哈哈XXX

Activity

  1. jfilter commented on Aug 26, 2021

    @jfilter
    Owner

    Hey @lemon234071, thanks for reporting. I'm not sure how to handle this. Right now, the URL has to be somehow separated from other tokes (e.g. by a preceding space). In your string, the URLs could be detected by using the ASCII characters in the string. Maybe this can be useful to add a special handling for Chinese texts? I would not adapt the current URL regex for English (etc.). https://github.com/jfilter/clean-text/blob/master/cleantext/constants.py#L62

  2. stellarissss commented on Jul 6, 2026

    @stellarissss

    Hi @jfilter,

    I came across this issue and found it really interesting, especially since it involves handling URLs within Chinese text.

    I’m a high school student with some experience in Python and GitHub. Since I’m a native Chinese speaker, I’m very familiar with how URLs often appear in Chinese sentences (like appearing without spaces or with typos like “http//”).

    I’d love to take a crack at fixing this! I’m also keen on helping improve the library’s Chinese support in the long run.
    If I eventually find that I cannot fix it, please also forgive me

    Could you please assign this issue to me? I’m happy to follow any contributing guidelines you have.

    Thanks!

  3. jfilter commented on Jul 6, 2026

    @jfilter
    Owner

    @stellarissss do it thanks

  4. stellarissss commented on Jul 7, 2026

    @stellarissss

    Hi @jfilter,

    I just submitted a PR to address this issue!

    While working on it, I realized that Chinese and CJK languages really need special handling because we don't use spaces between words. The fix I implemented extracts the CJK characters from mixed URLs and successfully supports all three CJK languages (Chinese, Japanese, and Korean).

    Regarding the "http//" typo mentioned in the original issue, I decided not to write specific code to clean it. After reading through the project's files, I felt that fixing typos might be out of scope for the URL replacement logic. I'd love to hear if my thinking is correct here!

    Thanks again for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions