[Question]
  [
Write a program or function that:
1. takes in a string from stdio or arguments
2. replaces all occurrences of `true` with `false` and `false` with `true`
3. reverses it, but does not reverse `true` and `false`
4. returns or prints result
Examples (left side is input):
```
"true"                     "false"
"2false"                   "true2"
"true is false"            "true si false"
"false,true,undefined"     "denifednu,false,true"
"stressed-false"           "true-desserts"
"falstrue"                 "falseslaf"
"true false true x"        "x false true false"
```
Standard loopholes apply.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in bytes wins.
### Leaderboard
```
var QUESTION_ID=63256,OVERRIDE_USER=20569;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
  
[Answer]
# C# 6, 144 bytes
```
string R(string t)=>string.Concat(new System.Text.RegularExpressions.Regex("true|false").Replace(t,m=>m.Value[0]<'g'?"eurt":"eslaf").Reverse());
```
It uses a regular expression to match `true|false`, and if it matches `true` it will be replaced by `eslaf`, otherwise by `eurt`. `m.Value[0]<'g'` is a shorter way to say `m.Value[0]=="false"`, because the only possible values for `m.Value` are `"true"` or `"false"`, so if the char code of the first char is smaller than the char code of `'g'`, it's `"false"`.
### Old version, 95 bytes
This one had a bug, it didn't return correct output for `falstrue`.
```
string R(string t)=>string.Concat(t.Reverse()).Replace("eurt","false").Replace("eslaf","true");
```
[Answer]
# [TeaScript](https://github.com/vihanb/TeaScript), ~~36~~ ~~25~~ 24 bytes
```
xv¬°g("eurt|eslaf",#ln>4)   
```
TeaScript is JavaScript for golfing.
Edits: Saved 11 bytes thanks to @V…™ ú·¥Ä…¥. Fixed for input `falstrue` and saved a byte.
Old version (Invalid):
```
xv¬°g("eurt",f)g(f.T¬°v¬°,t)
```
Explanation:
```
x    // Input
 v¬°    // Reverse
   g("eurt",    // Global replace "eurt" with "false".
            f)    // f is predefined to false.
              g(f.T¬°v¬°, // Convert false to string, then reverse.
                       t) // t is predefined to true.
```
[Answer]
## Bash+GNU, ~~45~~ ~~38~~ 73 bytes
**Edit:** works with both `trufalse` and `falstrue`
```
sed s/false/%eurt%/g\;s/true/%eslaf%/g|rev|sed "s/%\(true\|false\)%/\1/g"
```
**Old version**, 38 bytes (shortened, thanks to Digital Trauma):
```
rev|sed s/eurt/false/g\;s/eslaf/true/g
```
[Answer]
# JavaScript ES6, 59
As an anonymous function.
Note, replace is used just as a shorthand for match().map(). The replaced string is discarded, and the output string is made piece by piece backwards (so no need to reverse).
```
s=>s.replace(/false|true|./g,x=>s=(x[1]?x<'t':x)+s,s='')&&s
```
Test running the snippet below in an EcmaScript 6 compliant browser.
```
f=s=>s.replace(/false|true|./g,x=>s=(x[1]?x<'t':x)+s,s='')&&s
//test
console.log=x=>O.innerHTML+=x+'\n'
;[
 ["true","false"]
,["falstrue","falseslaf"]  
,["1false","true1"]
,["true is false","true si false"]
,["false,true,undefined","denifednu,false,true"]
,["stressed-false","true-desserts"]
,["true false true x","x false true false"]
].forEach(t=>console.log(t[0]+' -> '+f(t[0])))
```
```
<pre id=O></pre>
```
[Answer]
# Windows Batch, ~~184~~ 213 bytes
Fixed the bug, `falstrue -> falseslaf` and `trufalse -> trueurt`
Probably one of the less popular languages:
```
setlocal enabledelayedexpansion
set /p Q=
set N=0
:L
call set T=%%Q:~%N%,1%%%
set /a N+=1
if not "%T%" equ "" (
set R=%T%%R%
goto L
)
set R=%R:eurt=false%
set R=%R:eslaf=true%
set R=%R:falstrue=falseslaf%
echo %R%
```
[Answer]
# Haskell, 94 bytes
Performs pattern matching on the input string, looking for "false" or "true" and appends the opposite to the result of applying the function on the remainder of the string. If true or false isn't found, it uses recursion to reverse the string in the same fashion.
```
f[]=[]
f('t':'r':'u':'e':s)=f s++"false"
f('f':'a':'l':'s':'e':s)=f s++"true"
f(x:s)=f s++[x]
```
[Answer]
# JavaScript ES6, ~~95~~ 93 bytes
Unnamed function. Add `f=` to the beginning to use it. Thanks Ismael! Also assumes that the input does not contain tabs.
```
x=>[...x[r="replace"](/false/g,"\teslaf")[r](/(\t)*true/g,"eurt")[r](/\t/g,"")].reverse().join``
```
[Answer]
# Pyth, 30 bytes
```
::_z"eurt""false""eslaf""true"
```
This reverses the input (`_z`), substitutes `"eurt"` for `"false"` and `"eslaf"` for `"true"`. Replacement is done using `:`.
[Try it online](https://pyth.herokuapp.com/?code=%3A%3A_z%22eurt%22%22false%22%22eslaf%22%22true%22&input=true+is+false&debug=0)
[Answer]
# [rs](https://github.com/kirbyfan64/rs), 56 bytes
```
\t
+(.*\t)(.)(.*)/\2\1\3
\t/
eurt/fals\t
eslaf/true
\t/e
```
[Live demo and test cases.](http://kirbyfan64.github.io/rs/index.html?script=%5Ct%0A%2B%28.*%5Ct%29%28.%29%28.*%29%2F%5C2%5C1%5C3%0A%5Ct%2F%0Aeurt%2Ffals%5Ct%0Aeslaf%2Ftrue%0A%5Ct%2Fe&input=true%0A1false%0Afalstrue%0Atrue%20is%20false%0Afalse%2Ctrue%2Cundefined%0Astressed-false%0Afalstrue)
[Answer]
# Julia, ~~59~~ ~~55~~ 46 bytes
```
s->replace(reverse(s),r"eurt|eslaf",i->i<"et")
```
This creates an unnamed function that accepts a string and returns a string. To call it, give it a name, e.g. `f=s->...`.
The input is reversed using `reverse`. We match on the regular expression `eurt|eslaf` which matches `true` or `false` backwards. To the match we apply a function that returns `true` if the match is lexicographically smaller than `et` (i.e. `eslaf`) and `false` otherwise. The boolean literals are converted to string in the output.
Saved 9 bytes and fixed an issue thanks to Glen O!
[Answer]
# Javascript, 135 Bytes
```
function(s){return s.split("").reverse().join("").replace(/eslaf/i,'‚ò∫').replace(/eurt/i,'‚òª').replace(/‚òª/g,!1).replace(/‚ò∫/g,!1)}
```
## Test:
`=>`"false is the opposite of true"
`<=`"true fo etisoppo eht si false"
*Thanks ProgramFOX and edc65 for pointing out a bug!*
[Answer]
# Java, ~~162~~ ~~98~~ 92 bytes
Thanks (and sorry!~) to @DanielM. for telling me about StringBuffer and the fact that we can use functions!
[Because, you know, Java.](https://codegolf.meta.stackexchange.com/a/5829/44713)
```
s->(""+new StringBuffer(s.replaceAll("false","eurt")).reverse()).replaceAll("eurt","false");
```
Returns the correct, reversed string.
Ungolfed Version:
```
s->new StringBuilder(
    s.replaceAll("false","eurt"))
    .reverse().toString().replaceAll("eurt","false");
```
Basically, I replace all instances of "false" with a backwards "true", then reverse the entire string, and then replace the now backwards versions of "true" (not the ones I just replaced) with "false". Easy peasy.
[Answer]
# Mathematica, 64 bytes
```
StringReverse@#~StringReplace~{"eurt"->"false","eslaf"->"true"}&
```
[Answer]
# Python 3, ~~68~~ 100 bytes
I'm still golfing it, but it's fixed to the bug, so `falstrue -> falselsaf` and `trufalse -> trueurt`
Pretty straightforward:
```
print(input()[::-1].replace("eurt","false").replace("eslaf","true").replace("falstrue","falseslaf"))
```
[Answer]
# Japt, 26 bytes
**Note:** This may be invalid, as it requires bug fixes made after this challenge was posted.
```
Uw r"eurt|eslaf",X=>X<"et"
```
Try it in the [online interpreter](https://codegolf.stackexchange.com/a/62685/42545)! (Arrow function requires ES6-compliant browser, such as Firefox.)
### How it works
```
             // Implicit: U = input string
Uw r         // reverse U, then replace:
"eurt|eslaf" // occurrences of either "eurt" or "eslaf"
X=>X<"et"    // with "false" or "true", respectively
             // Implicit: output last expression
```
Here's a version that worked before the bug fixes: (38 bytes)
```
Uw $.replace(/eurt|eslaf/g,X=>X<"et")$
```
[Answer]
## Gema, 43
```
*=@a{@reverse{*}};a:eurt=false;a:eslaf=true
```
([Gema](http://gema.sourceforge.net/new/index.shtml) is an obscure macro language.)
[Answer]
# Pyth, ~~28~~ 22
```
Amr`!dZ2jHjLGcR_Hc_z_G
```
6 bytes thanks to Jakube
Works correctly for `falstrue`, as shown in the suite below.
[Test suite](https://pyth.herokuapp.com/?code=Amr%60%21dZ2jHjLGcR_Hc_z_G&input=falstrue&test_suite=1&test_suite_input=true%0A2false%0Atrue+is+false%0Afalse%2Ctrue%2Cundefined%0Astressed-false%0Afalstrue%0Atrue+false+true+x&debug=0)
[Answer]
# Haskell, 102 bytes
```
h('t':'r':'u':'e':s)="eslaf"++h s
h('f':'a':'l':'s':'e':s)="eurt"++h s
h(x:s)=x:h s
h[]=""
r=reverse.h
```
The replacement of "true" by "false" and vice-versa is quite lengthy with the pattern-matching, but at least it deals correctly with "falstrue" and the like. And besides, I suspect that a correct regex-based version would be a bit longer.
[Answer]
## Python 3 - 108 92 bytes
```
import re
print(re.sub("eslaf|eurt",lambda m:repr(len(m.group(0))>4).lower(),input()[::-1]))
```
Uses a regex to match on "true" or "false" and uses a lambda to process matches and choose what to use as a replacement string. Using repr gets the string representation of (len(match)>4) which gives "True" when "false" is matched and vice versa (and use .lower() because repr(bool) gives a capitalized string) to get the inverse of the match and finish up by reversing the replacement and then the processed input using [::-1] 
Managed to get the length down 16 bytes from TFelds suggestions.
Edit: Python is back in front of java, no need for alarm.
[Answer]
# ùîºùïäùïÑùïöùïü, 40 chars / 65 bytes
```
√¥[‚Ä¶√Øƒã/false|true/g,‚áè[‚Ä¶‚¨Ø+!◊©√∫a]√π‚¨Æ√∏‚¨Ø)]√π‚¨Æ√∏‚¨Ø)
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter.html?eval=false&input=falstrue&code=%C3%B4%5B%E2%80%A6%C3%AF%C4%8B%2Ffalse%7Ctrue%2Fg%2C%E2%87%8F%5B%E2%80%A6%E2%AC%AF%2B!%D7%A9%C3%BAa%5D%C3%B9%E2%AC%AE%C3%B8%E2%AC%AF%29%5D%C3%B9%E2%AC%AE%C3%B8%E2%AC%AF%29)`
Thanks to @feersum for pointing out a bug!
## 21 chars / 43 bytes, non-competitive
```
√¥·¥ô(√Øƒã/‚ä≠|‚ä®‚åø,‚Ü™·¥ô(‚¨Ø+!√´$‚∏©‚∏©
```
`[Try it here (Firefox only).](http://molarmanful.github.io/ESMin/interpreter.html?eval=false&input=asdfoiansfoinqwoiefnasdonaonfitrueaosdifnofalse&code=%C3%B4%E1%B4%99%28%C3%AF%C4%8B%2F%E2%8A%AD%7C%E2%8A%A8%E2%8C%BF%2C%E2%86%AA%E1%B4%99%28%E2%AC%AF%2B!%C3%AB%24%E2%B8%A9%E2%B8%A9)`
[Answer]
# Prolog, 225 bytes
```
p(X):-string_to_list(X,L),reverse(L,B),q(B,C),string_to_list(Z,C),write(Z),!.
q([],[]).
q([101,117,114,116|T],[102,97,108,115,101|L]):-q(T,L).
q([101,115,108,97,102|T],[116,114,117,101|L]):-q(T,L).
q([H|T],[H|L]):-q(T,L).
```
Try it out online [here](http://swish.swi-prolog.org/)
  
Run by querying in the following way:  
```
p("falstrue").
```
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 15 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
√îr`laf|e¬®t`√à√∏f
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=1HJgg2xhZnxlqHRgyPhm&input=WwoidHJ1ZSIKIjJmYWxzZSIKInRydWUgaXMgZmFsc2UiCiJmYWxzZSx0cnVlLHVuZGVmaW5lZCIKInN0cmVzc2VkLWZhbHNlIgoiZmFsc3RydWUiCiJ0cnVlIGZhbHNlIHRydWUgeCIKXS1tUg)
[Answer]
# Ruby, 55 bytes
```
->s{s.gsub(/true|false/){$&[?t]?:eslaf: :eurt}.reverse}
```
Test:
```
->s{s.gsub(/true|false/){$&[?t]?:eslaf: :eurt}.reverse}["false,true,undefined"]
=> "denifednu,false,true"
```
[Answer]
## Perl 5, 68 bytes
67 plus 1 for `-E` instead of `-e`
```
%a=(false,eurt,true,eslaf);say~~reverse<>=~s/false|true/$a{$&}/gr
```
[Answer]
# OpenSCAD, 178 bytes
(Note that this uses the [String Theory library](http://www.thingiverse.com/thing:526023), as OpenSCAD doesn't exactly have a standard library. Additionally, this is a function because the only allowed input is to hard-code it.
```
use <Strings.scad>;function f(a)=contains(g(a),"eurt")?replace(g(a),"eurt","false"):g(a);function g(a)=contains(reverse(a),"eslaf")?replace(reverse(a),"eslaf","true"):reverse(a);
```
[Answer]
## C#, 260 bytes
```
using System;class P{static void Main(){var y=Console.ReadLine();char[] n=y.ToCharArray();Array.Reverse(n);var s=new string(n);if(s.Contains("eslaf")){s=s.Replace("eslaf","true");}if(s.Contains("eurt")){s=s.Replace("eurt","false");}Console.WriteLine(s);}}
```
[Answer]
## PHP, 60 bytes
Simple, reverses the string first, then replaces the reversed versions with their respective swaps.
"falstrue" becomes "eurtslaf" becomes "falseslaf".
```
<?=strtr(strrev($argv[1]),{'eurt'=>'false','eslaf'=>'true'})
```
[Answer]
## Perl 5.10, 54 bytes
```
$_=reverse<>;s/(eurt)|(eslaf)/$1?"false":"true"/eg;say
```
Reverse, then replace. A different way of doing it besides the hash table used for the other Perl answer, which ends up being shorter!
[Try it online.](https://ideone.com/TZ7kPL)
[Answer]
# Pyth - 18 bytes
Can be golfed a lot more.
```
Amr`!dZ2::_z_GH_HG
```
[Test Suite](http://pyth.herokuapp.com/?code=Amr%60%21dZ2%3A%3A_z_GH_HG&test_suite=1&test_suite_input=true%0A1false%0Atrue+is+false%0Afalse%2Ctrue%2Cundefined%0Astressed-false&debug=0).
]