正则表达式移动答案反馈到答案之前?



我为题库准备了一些文本问题。它们需要重新格式化,我不知道如何在问题和答案选项之间移动反馈。反馈以"@"开头。"*"表示正确答案。最初的反馈只针对一个正确的答案,但我们的新LMS只支持任何不正确的答案的一般反馈。我如何将@后面的反馈文本移动到第一个答案选择之前?

32) This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  This is the question text.  
*a. 091°.
@ (Chapter - Section)
This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  This is the feedback.  
b. 095°.
c. 099°.

您可以通过使用正则表达式^(d+).*nn)((?:*?[a-z]. .*n)*)(@ .*n.*n)((?:*?[a-z]. .*n)*)和替换字符串$1$3n$2$4来做到这一点。

这里regex的意思是:

  • ^(d+).*nn)行,以数字、右括号和空格开头,后跟两行,
  • ((?:*?[a-z]. .*n)*)行以可选的*、字母、点和任意数量的任意符号开头,重复任意次数。任意数量的答案。
  • (@ .*n.*n)两行,首先以@(feedback)
  • 开头
  • ((?:*?[a-z]. .*n)*)和以前一样

替换的演示可以在这里看到。此外,您还可以修补替换字符串,因为您没有提供足够的输入来可靠地猜测期望的输出。

要使用此功能,请使用VScode或Sublime Text打开文件:
打开替换视图Ctrl+H
确保启用选项Use regular expression
粘贴正则表达式和替换字符串。
替换所有Ctrl+Alt+Enter

编辑:考虑多行反馈
^(d+).*n+)((?:*?[a-z]. .*n)*)(@ .*(?:n.*)*?n(?=[a-z].|nd+)|nn))((?:*?[a-z]. .*n)*)

相关内容

最新更新