I need to change several text files with questions to a format which a online learning platform uses.
I have lines with this structure:
\item Question in german.//Question in english.\\ %true
\item Second question in german.//Second question in english.\\ %false
I need to change the line so it would look like this:
::Question in german.//Question in english.::[html]<p><span style\="font-size\: 14px;">Question in german.//Question in english.</span><br></p>{ %true
::Second question in german.//Second question in english..::[html]<p><span style\="font-size\: 14px;">Second question in german.//Second question in english.</span><br></p>{ %false
Only the text 'Question in german.//Question in english.' and the anser '%true' changes (the answer can either be true or false).
I was able to find my wanted part with this regex expression:
(\\item )(.*)(\\\\ %.*)
I used this::\2::[html]<p><span style\="font-size\: 14px;">\2</span><br></p>{ \3
as replacement statement but Notepad++ result is:
::::[html]<p><span style="font-size: 14px;"></span><br></p>{
I also tried
:: $2 ::[html]<p><span style\="font-size\: 14px;"> $2 </span><br></p>{ $3
because I'm not sure what Syntax notepad++ v7.7 uses. The result is similar
:: ::[html]<p><span style="font-size: 14px;"> </span><br></p>{
I have no idea why Notepad++ ignores my groups.
SOLUTION
I wasn't able to solve the problem with Notepad++. Here is the solution that worked for me:
I used this webpage https://regex101.com/ with the pattern to search:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)
and for substitiution::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3
Try the following find and replace, in regex mode:
Find: ^\\\S+\s+(.*?)//(.*?)\\\\ %true$
Replace: ::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ %true
Your current pattern is not specific enough, and also the (.*)
capture group might possibly match incorrectly across lines, depending on the regex mode being used.
I wasn't able to solve the problem with Notepad++. Here is the solution that worked for me:
I used this webpage https://regex101.com/ with the pattern to search:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)
and for substitiution::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3
Here is the link to the solution DEMO
Credit goes to bobblebubble and TimBiegeleisen
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.