in Education by
I've got strings like these: | Released = {{start-date|June 14, 1972}} | Released = {{Start date|1973|03|01|df=y}} I'd like to replace all | within {{ }} with ^ | Released = {{start-date^June 14, 1972}} | Released = {{Start date^1973^03^01^df=y}} I can't use substring replacement because there are | symbols outside {{ }}, which must be left intact. And because I don't know exactly how many parts does the string in {{ }} have, I can't use something like s/{{(.+?)\|(.+?)}}/{{$1^$2}}/. I suppose I need to use some kind of recursion here? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
A simple solution: s/\|(?=[^{}\n]*}})/^/g Even simpler solution, but probably broken in many cases: s/(?!^)\|/^/gm Here is a bit more robust regex: s/(?:\G(?!^)(?:(?>[^|]*?}})(?>.*?{{))*|^(?>.*?{{))(?>[^|]*?(?=}}|\|))\K\|(?=.*?}})/^/gs; Commented: s/ (?: \G(?!^) # inside of a {{}} tag (?: (?>[^|]*?}}) (?>.*?{{) )* # read till we find a | in another tag if none in current | ^(?>.*?{{) # outside of tag, parse till in ) (?> [^|]*? (?=}}|\|) ) # eat till a | or end of tag \K # don't include stuff to the left of \K in the match \| # the | (?=.*?}}) # just to make sure the tag is closed /^/gsx; Input: |}} | Re|eased = {{start-date|June 14^, {|1972}|x}} | Released = {{Start date}|1973|03|01}|df=y|}} | || {{|}} {{ | Output: |}} | Re|eased = {{start-date^June 14^, {^1972}^x}} | Released = {{Start date}^1973^03^01}^df=y^}} | || {{^}} {{ | Example: http://ideone.com/fbY2W

Related questions

0 votes
    From the server, I receive this JSON object. It represents an organigram of a company and the associated ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    From the server, I receive this JSON object. It represents an organigram of a company and the associated ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I need to make a table with data with nested subtasks. I need to make this table recursive. There ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve ... pdf, mcq on JavaScript pdf, JavaScript questions and s...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 17, 2022 in Education by JackTerrance
0 votes
    SA=1000.00 AI=0.12 MP=100.00 def remainb(x): if x==0: return 0 else: return x=(SA+(AI/12)*SA)-MP for ... . run the loop until SA==0). Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    Write C program that use both recursive and non recursive functions to perform Linear search for a Key value in a given list. Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Which of these will happen if recursive method does not have a base case? (a) An infinite loop ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    What is the meaning of recursive hints in Oracle?...
asked Dec 18, 2020 by JackTerrance
0 votes
    What is a Recursive Stored Procedure?...
asked Dec 11, 2020 in Technology by JackTerrance
0 votes
0 votes
    For instance, given ( 1, 2, 5, 6, 7), i'd like to determine that 3 and 4 are missing? ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 14, 2022 in Education by JackTerrance
0 votes
    For instance, given ( 1, 2, 5, 6, 7), i'd like to determine that 3 and 4 are missing? ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    How do I use Perl to create graphs? I'm running scheduled job that creates text reports. I'd like ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    How do I use Perl to create graphs? I'm running scheduled job that creates text reports. I'd like ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
...