Skip to content

What exactly should the result of \s*#[^"']+$ be? #12775

Open
@anywo

Description

@anywo

What would you like to share?

Code

import re
a = """
py_path = os.path.abspath(sys.argv[0])  # Absolute path of the current script  
str = '#FFFFFF'  # Color  
py_dir = os.path.dirname(py_path)  # Directory where the current script is located  
"""
pattern = '\\s*#[^"\']+$'
regex = re.compile(pattern, flags=re.MULTILINE) if isinstance(pattern, str) else pattern
print(re.sub(regex, "", a))

Expected behavior


py_path = os.path.abspath(sys.argv[0])
str = '#FFFFFF'
py_dir = os.path.dirname(py_path)

Actual behavior


py_path = os.path.abspath(sys.argv[0])
str = '#FFFFFF'

VsCode Result(Consistent with my understanding)

Image

Js Result

Image

Java Result

Image

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting triageAwaiting triage from a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions