Posted to tcl by doctaxon at Fri Feb 05 15:20:19 GMT 2016view raw

  1. set contents {
  2.  
  3. {{QS-Medizin|1=Jetzt anders herum [[Benutzer:Partynia|Partynia]] <sup>[[Benutzer Diskussion:Partynia|∞]] [[WP:RM|RM]]</sup> 07:40, 5. Feb. 2016 (CET)}}
  4.  
  5. Test nach [[Wikipedia:Redaktion Medizin#Vorlage QS-Medizin]]
  6.  
  7. Diese {{Vorlage|Vorlage}} ist eine Vorlage zum Test.}
  8.  
  9. #----
  10.  
  11. regexp -nocase -- {\{\{QS-Medizin\|(?:1=|2=)??(.*?)\}\}} $contents -- reason
  12.  
  13.  
  14. %puts $reason
  15. 1=Jetzt anders herum [[Benutzer:Partynia|Partynia]] <sup>[[Benutzer Diskussion:Partynia|∞]] [[WP:RM|RM]]</sup> 07:40, 5. Feb. 2016 (CET)
  16.  
  17. ----
  18. But I added into the regex this: (?:1=|2=)??
  19. So I guess, that 1= and 2= are not matched in $reason. But the match begins with 1=
  20.  
  21.  
  22. The needed match is (without leading 1=):
  23.  
  24. %puts $reason
  25. Jetzt anders herum [[Benutzer:Partynia|Partynia]] <sup>[[Benutzer Diskussion:Partynia|∞]] [[WP:RM|RM]]</sup> 07:40, 5. Feb. 2016 (CET)
  26.  
  27.  
  28.  
  29. What is wrong?
  30.  
  31.  
  32.  
  33.  

Comments

Posted by apn at Fri Feb 05 16:07:47 GMT 2016 [text] [code]

But my point was that (?:1=|2=)? immediately makes the 1= optional and it falls into the (.*) part which is why you see it in reason

Posted by apn at Fri Feb 05 16:10:18 GMT 2016 [text] [code]

% regexp -nocase -- {\{\{QS-Medizin\|(1=|2=){1,1}?(.*)\}\}} $contents x x reason ; set reason Jetzt anders herum [[Benutzer:Partynia|Partynia]] <sup>[[Benutzer Diskussion:Partynia|∞]] [[WP:RM|RM]]</sup> 07:40, 5. Feb. 2016 (CET)

Posted by apn at Fri Feb 05 16:12:23 GMT 2016 [text] [code]

Or this % regexp -nocase -- {\{\{QS-Medizin\|(?:1=|2=){1,1}?(.*)\}\}} $contents x reason ; set reason Jetzt anders herum [[Benutzer:Partynia|Partynia]] <sup>[[Benutzer Diskussion:Partynia|∞]] [[WP:RM|RM]]</sup> 07:40, 5. Feb. 2016 (CET)

Posted by apn at Fri Feb 05 16:17:57 GMT 2016 [text] [code]

Sorry, my attempts are incorrect

Posted by doctaxon at Fri Feb 05 17:51:56 GMT 2016 [text] [code]

Here the solution with thanks to gifti: regexp -nocase -- {(?:\{\{QS-Medizin\|(?:1=|2=)?(.*?)\}\}){1,1}?} $contents -- reason