Skip to content

Syntax warning from ROR check #7

@timj

Description

@timj
elinkapi/utils.py:5: SyntaxWarning: invalid escape sequence '\/'
  _ROR_ID_PATTERN = re.compile("^(?:(?:(http(s?):\/\/)?(?:ror\.org\/)))?(0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2})$")

This is because it's not a raw string.

This works:

_ROR_ID_PATTERN = re.compile(r"^(?:(?:(http(s?)://)?(?:ror\.org/)))?(0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2})$")

I don't think the / needs to be escaped at all but the "." does.

Example showing it working:

>>> _ROR_ID_PATTERN = re.compile(r"^(?:(?:(http(s?)://)?(?:ror\.org/)))?(0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2})$") 
>>> _ROR_ID_PATTERN.match("https://ror.org/048g3cy84")
<re.Match object; span=(0, 25), match='https://ror.org/048g3cy84'>
>>> _ROR_ID_PATTERN.match("https://ror.org/048g3cy84dfg ")
>>> 

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