JavaScript Regex Ternary string -


I am using an esoteric general and filarer with the encrypted user for the desired static assets.

Things were working in JS files well for the angular HTML template replacement unless we ran into a case with other operators

  if ( $ Scope.isPdf) {$ scope.templateUrl = '/ thoughts / results / breaks -detailed.html'; } And {$ scope.templateUrl = '/views/results/breakdown.html'; }  

After converting things into a line turner operator

  $ scope.templateUrl = $ scope.isPdf? "/ View / results / breakdowns - longer target not to capture all html issues for replacement string to replace regex     / TemplateUrl \ s? [: =] \ S? [']] ([^ "'] +) ["] / Gm  

Does anyone have a regex which is both values

$ scope.templateUrl = $ scope.isPdf ($ Scope.). IsPdf) {$ scope.templateUrl = '} "/" / views / results / breakdown-detail.html ":" / view / Result / breakdown.html "}}

  /views/results/breakdown-detailed.html ';} Other {$ scope.templateUrl =' /views/results/breakdown.html ' ;}  

I'll throw in the test Regexr to try it out

use the form regex

  templateUrl (([^ ?] *) \? ([^:] *): ([^;] *) | (\ S * = \ s *) [^;] *)   

Jo Anything is followed by templateUrl

See for example how regex matches.

Explanation

  • templateUrl match templateUrl

    < / Li>
  • ([^?] *) \? ([^:] *): ([^;] *) matches Ternary operator

    • ([^?] *) \? ?

    • ([^:] :

    • < P> ([^
    • (\ s * = matches .

      • (\ s * = \ s *) matches = < / Li>
      • [^;] *) matches anything other than ;

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -