Skip to content

Script: pass raw string as regex pattern#2787

Open
Alex-Jordan wants to merge 1 commit intoPreTeXtBook:masterfrom
Alex-Jordan:syntaxwarning
Open

Script: pass raw string as regex pattern#2787
Alex-Jordan wants to merge 1 commit intoPreTeXtBook:masterfrom
Alex-Jordan:syntaxwarning

Conversation

@Alex-Jordan
Copy link
Contributor

My python version is 3.12.8. When I use the pretext script, I get these warnings:

/Users/alex.jordan/pretext/pretext/lib/pretext.py:2764: SyntaxWarning: invalid escape sequence '\['
  qtext = re.sub("\[\[validation:(\w+)\]\]", "", qtext)
/Users/alex.jordan/pretext/pretext/lib/pretext.py:2765: SyntaxWarning: invalid escape sequence '\['
  qtext = re.sub("\[\[feedback:(\w+)\]\]", "", qtext)
/Users/alex.jordan/pretext/pretext/lib/pretext.py:2768: SyntaxWarning: invalid escape sequence '\['
  ansids = re.findall("\[\[input:(\w+)\]\]", qtext)

The change here is so that a raw string, with literal backslash and literal bracket will be passed as the regex pattern. Then the regex itself will use the backslash to escape the bracket in pattern matching.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant