[Question]
  [
Title ~~stolen~~ inspired by [Greg Hewgill's answer](//stackoverflow.com/a/245068) to [What's the difference between JavaScript and Java?](//stackoverflow.com/q/245062)
# Introduction
Java and JavaScript are commonly used languages among programmers, and are currently the [most popular](//stackoverflow.com/tags) tags on Stack Overflow. Yet aside from similar names, the two have almost nothing in common.
In honor of one of programming's most infamous debates, and [inspired by my recent frustrations in tag searching](//meta.stackexchange.com/q/297703), I propose the following:
# Challenge
Write a program which takes in a string as input. Return `car` if the string begins with "Java" and *does not* include "JavaScript". Otherwise, return `carpet`.
# Example Input and Output
### car:
```
java
javafx
javabeans
java-stream
java-script
java-8
java.util.scanner
java-avascript
JAVA-SCRIPTING
javacarpet
```
### carpet:
```
javascript
javascript-events
facebook-javascript-sdk
javajavascript
jquery
python
rx-java
java-api-for-javascript
not-java
JAVASCRIPTING
```
# Notes
* Input matching should be case insensitive
* Only possibilities for output should be `car` or `carpet`
* Imaginary bonus points if your answer uses Java, JavaScript, or Regex
* Alternate Title: *Java is to JavaScript as ham is to hamster*
  
[Answer]
# Java/JavaScript Polyglot, ~~108~~ ~~107~~ 106 bytes
```
//\u000As->s.matches("(?i)(?!.*javascript)java.*"/*
a=>/(?!.*javascript)^java/i.test(a/**/)?"car":"carpet"
```
## Run as Java
```
//\u000As->s.matches("(?i)(?!.*javascript)java.*"/*
a=>/(?!.*javascript)^java/i.test(a/**/)?"car":"carpet"
```
[Try it online!](https://tio.run/##bVJda8IwFH33V2QFoS0mFfYydCoy2HCwMebYyz4g1lSjbZLl3ooy/O2uX6jtfGhvzsm5J/fmZsU3nGoj1Gq@Pph0FsuQhDEHIE9cKvLbIqRiATlmYaPlnCTZnjtFK9Xi44twuwCvkBKyyvxYijJmUapClFqx@2pxWyZ0yjAkERkcguAz7Xa7Y6BDYAnHcCnAddyR9NzRFfNzNwitNOgVxr4T@C0@GAbN3e98HUiGAtDlge8H3sgJuXV6@d8IdA79or5j0bkSyKAqmxAnd3A65yja1vFMcAV1igJawZMmWRTVIG/quLwkCLlSwjakx75O/OP4fUynd6@Tl7fJ80Ndf@m4kqNiIxSe1RzxUMy0XtMzDczX9dyLnj@psLsTNjtcanXCdkv/XyDlRtJIW3rJUWlspOQ9Nlvc91tFzFyqB1dMrlfOzzuOb7oDFAnTKTKTqTBynfZ1F3qkDe2szELeIRHjxsQ7N0eeV76IfSv/9oc/ "Java (OpenJDK 8) – Try It Online")
Note: don't trust the highlight as it's incorrect. The real Java, properly interpreted looks like below because `\u000A` is interpreted in the very first step of the compilation as `\n`, de facto ending the comment that started with the line comment (`//`).
```
//
s->s.matches("(?i)(?!.*javascript)java.*"/*
a=>/(?!.*javascript)^java/i.test(a/**/)?"car":"carpet"
```
## Run as JavaScript
```
//\u000As->s.matches("(?i)(?!.*javascript)java.*"/*
a=>/(?!.*javascript)^java/i.test(a/**/)?"car":"carpet"
```
Credits to @CowsQuak for the JS version.
```
let f=
//\u000As->s.matches("(?i)(?!.*javascript)java.*"/*
a=>/(?!.*javascript)^java/i.test(a/**/)?"car":"carpet"
var a=["java","javafx","javabeans","java-stream","java-script","java-8","java.util.scanner","javascript","java-avascript","javascript-events","facebook-javascript-sdk","javajavascript","jquery","python","rx-java","java-api-for-javascript","not-java"];
for(var s of a) console.log(s.padStart(a.reduce((x,y)=>x.length>y.length?x:y).length) + "=>" + f(s));
```
How many imaginary bonus points for this answer?
-1 byte thanks to [@Nevay](https://codegolf.stackexchange.com/questions/132272/java-is-to-javascript-as-car-is-to-carpet?noredirect=1#comment324764_132279) in the Java answer.
[Answer]
# JavaScript, ~~50~~ 49 bytes
*Saved 1 byte thanks to @ValueInk by rearranging the regex*
```
a=>/javascript|^(?!java)/i.test(a)?"car":"carpet"
```
### Test snippet
```
let f=
a=>/javascript|^(?!java)/i.test(a)?"carpet":"car"
var a=["java","javafx","javabeans","java-stream","java-script","java-8","java.util.scanner","java-avascript","javascript","javascript-events","facebook-javascript-sdk","javajavascript","jquery","python","rx-java","java-api-for-javascript","not-java"];
for(var s of a) console.log(s.padStart(a.reduce((x,y)=>x.length>y.length?x:y).length) + "=>" + f(s));
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~92~~ ~~82~~ ~~72~~ ~~58~~ 57 bytes
```
s->s.matches("(?i)(?!.*javascript)java.*")?"car":"carpet"
```
[Try it online!](https://tio.run/##bVJNawIxEL37K9KAsCsmFHopWhUptFhoKbX0UnqIMavR3STNzEql@Nu3@4W6Ww@byXv75mUmk43YCWadMpvlNnPpItaSyFgAkGehDfntEFKzgALzsLN6SZL8XzBHr83q84sIv4KwlBKyyf14ijrmUWokamv4Q725qxL6VRiTiIwyYGPgiUC5VhDQYKLDYHLFe4ULSK8dhqVhj4YTKoWng2J1Cmk2LI871oAKEMioroIQWuTR/jmKfpp4oYSBJsUAvRJJmywraZG3TVz1DFIYo3xLemzmxD9NP6Zsfv82e32fvTw29ZeOqzimdsrgWc2RkGph7ZadaWC5beZe9PxOld@fsNvj2poT9j/s/wUy4TSLrGeXHI3FVkrRY7vFw7BTxtylfj/l5AbV/MLj@OZ7QJVwmyJ3uQqjgHZvrmFAutDNyyzlfRJx4Vy8DwoUhtWLOHSK75D9AQ "Java (OpenJDK 8) – Try It Online")
1 byte saved thanks to [@Nevay](https://codegolf.stackexchange.com/questions/132272/java-is-to-javascript-as-car-is-to-carpet?noredirect=1#comment324764_132279)!
[Answer]
# C (only calling puts), 131 bytes
```
f(int*s){char r[]="carpet";~*s&'AVAJ'||(r[3]=0);for(;*s&255;*(int*)&s+=1)~*s&'AVAJ'||~s[1]&'IRCS'||~s[2]&'TP'||(r[3]='p');puts(r);}
```
It does have its problems, but it passes all of the testcases provided :)
```
g(int* s)
{
  char r[] = "carpet";
  ~*s&'AVAJ' || (r[3]=0);
  for(;*s & 255; *(int*)&s +=1)
    ~*s&'AVAJ' || ~s[1]&'IRCS' || ~s[2]&'TP' || (r[3]='p');
  puts(r);
}
```
> 
> Imaginary bonus points if your answer uses Java, Javascript, or Regex
> 
> 
> 
well... no thanks
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 21 bytes
```
lD'¦‚å≠sη'îáå*„¾„ƒ´#è
```
[Try it online!](https://tio.run/##ATsAxP8wNWFiMWX//2xEJ8Km4oCaw6XiiaBzzrcnw67DocOlKuKAnsK@4oCexpLCtCPDqP//amF2YXNjcmlwdA "05AB1E – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), 68 bytes
```
k=input().lower();print'car'+'pet'*(k[:4]!='java'or'javascript'in k)
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P9s2M6@gtERDUy8nvzy1SEPTuqAoM69EPTmxSF1bvSC1RF1LIzvayiRW0VY9K7EsUT2/CEwXJxdlFpSoZ@YpZGv@/68UADZPCQA "Python 2 – Try It Online")
-11 bytes thanks to [notjagan](https://codegolf.stackexchange.com/users/63641/notjagan)  
-2 bytes thanks to [Dennis](https://codegolf.stackexchange.com/users/12012/Dennis) 
[Answer]
# C#, ~~80~~ 78 bytes
```
s=>(s=s.ToLower()).StartsWith("java")&!s.Contains("javascript")?"car":"carpet"
```
[Answer]
# ~~EXCEL~~ Google Sheets, ~~89~~ 86 Bytes
Saved 3 bytes thanks to Taylor Scott
```
=LEFT("carpet",6-3*ISERR(SEARCH("javascript",A1))+3*ISERR(IF(SEARCH("java",A1)=1,1,1/0
```
Takes an input on A1
### Explanation
```
=LEFT("carpet",6-3*ISERR(SEARCH("javascript",A1))+3*ISERR(IF(SEARCH("java",A1)=1,1,1/0)))
 SEARCH("javascript",A1)        #Case-Insensitive Find, returns error if not found  
 ISERR(                         #Returns string true if error, False if not
 3*ISERR(                       #Forces TRUE/False as integer, multiplies by 3
 IF(SEARCH("java",A1)=1,1,1/0)  #If java found, returns integer. if 1, java begins string
                                #so returns 1, which will be turned into 0 by iserr.
                                #Else returns 1/0, which will be turned into 1 by iserr.
 LEFT(                          #Returns digits from the left, based upon count.
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 27 bytes
```
,“Ẋṣ“®Ẓȷ»ŒlwÐ€/Ḅn2‘×3“¢Ẹị»ḣ
```
[Try it online!](https://tio.run/##y0rNyan8/1/nUcOch7u6Hu5cDGQcWvdw16QT2w/tPjopp/zwhEdNa/Qf7mjJM3rUMOPwdGOQgkUPd@14uLv70O6HOxb/f7h7y@F2oKLI//@zEssSuUBEWgWYSkpNzCsGs3SLS4pSE3Oh7OSizIISCNsCTOmVlmTm6BUnJ@blpRZBJIAYqs7LMcxRN9g5yDMgxNPPHSyLZAKEqZtalppXUsyVlpicmpSfn62LJFWckg1WiayxsDS1qJKroLIkIz@Pq6hCF@5y3cSCTN20/CIkA7jy8ksgCkAugTsEAA "Jelly – Try It Online")
[Answer]
# vim, 58 bytes
```
gUU:s/.*JAVASCRIPT.*/Q/g
:s/^JAVA.*/car
:s/[A-Z].*/carpet
```
[Try it online!](https://tio.run/##K/v/Pz001KpYX0/LyzHMMdg5yDMgRE9LP1A/nQsoGgcSBHKTE4tA3GhH3ahYCLcgteT//6zEskTdxIJM3bT8Il0Qpzi5KLOgBAA "V – Try It Online")
[Answer]
# [Ruby](https://www.ruby-lang.org/), 42+1 = 43 bytes
Uses the `-p` flag.
```
$_="car#{"pet"if~/javascript|^(?!java)/i}"
```
[Try it online!](https://tio.run/##TY9NT8MwDIbv@RUm9LBJSytuCGmbph2mcUAIEEemNKRa2OYEJ51W8fHTCWuKSi/xE72284TqsomODAYYZTnM4ArmkBVwA2j24wlkm1xt7cFNgMN0BjxmmylXki4/uNOBm@q7eJNH6RUZFz5fRvOL9jouzBePsUXWHtUplVJL9ImED6Tl4Y/TcMfXqeR1MPvcK4moqQv6R9jt4nkhHpcP6/un9d0qpWehsw37Nxmg0EeNwbNKKl1auxODyL/uUudw8L3W1DDXhK1FRifRf0JIZ0RlabCAoQ1dQyvVO/1YF4xFH4X7BQ "Ruby – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~44~~ 37 bytes
```
Ai`^(?!.*javascript)java
.+
pet
^
car
```
*Thanks to @MartinEnder for golfing off 7 bytes!*
[Try it online!](https://tio.run/##TY5BD4IwDIXv/RceTFAzzt4M8UDwYIwaj4SCJU50m9sg8OtnGAZ3ab@0r69Pk@UC3TJKC5fwIo92i3j9xA5NpbmyqxEh3oAiCzlUqJ3zo7HUvW8loTCemLGa8P1jbzDx1re4tfwVmwqFID0t5kdwSG4Ju@zP2emaHVP4RwiQUUfCGqixolLKhgUrc2@8Mjz8tKQHUIN9SAG6Z3NyhoqzWurAAIS0k2BMMgf5Ag "Retina – Try It Online")
[Answer]
# Common Lisp, ~~131~~ 125 bytes
```
(lambda(s)(format()"car~@[pet~]"(or(<(length s)4)(not(#1=string-equal"java"(subseq s 0 4)))(search"javascript"s :test'#1#))))
```
[Try it online!](https://tio.run/##VZHBTsMwDIZfxeqE5hwyMTQkhAAxcUDjgBAgLhMHt3O3si7p4nTqLn31kbJ2dIckv5XPjv0nyTMpDphbW0BqHVSQGRhi9EM7iuDvSKtWxExGWq3FO6bNKUpcVvguumnFqPRZPpKEjGHXXYZ1ol@mX1P98fQ@e/ucvT63REKu4K7WWeFjoHnHxjeNpJRwbO1a9y5lsW7p8/RtyW4fRLH3K2uCcJXuDampyHQwQJ9lGes7qGn1v1O1sBjoDXnwENVX1wT6AWqqL6JgIQZDaRMvCEW1GKoozFU/zsNo9XeE1uEd5myWfgWiJgrDUzgY3wdbM7PUvC0pP34CShkLb0HgEiZKKRQml6z67gjcehY/HIwHAVCHqtl@AQ)
Size reduced thanks to the [#n=](http://www.lispworks.com/documentation/HyperSpec/Body/02_dho.htm) “trick” of Common Lisp.
**Explanation**
```
(lambda (s)                 ; anonymous function
  (format                   ; use of format string to produce the result
    ()                      ; the result is a string
    "car~@[pet~]"           ; print "car", then print "pet" when:
    (or (< (length s) 4)    ; the string is less then 4 characters or
        (not (string-equal "java" (subseq s 0 4)))     ; does not start with java or
        (search "javascript" s :test 'string-equal)))) ; contains javascript
```
[Answer]
# [Python 2](https://docs.python.org/2/), 69 bytes
```
f=input().lower().find
print'car'+'pet'*(f('java')!=~f('javascript'))
```
Currently 1 byte longer than the shortest Python 2 solution.
[Try it online!](https://tio.run/##TVCxbsMgFNz5Cjo90wgPnapUHqIOUTpUVVt1x/ih0DhAAafO0l93MVitB3gn3XHcPXeNR2vuJmU9DVQbCgDkU1xEvtSYR4vChIx4iB7FecHSaxcLvs@jHqLu6yCFMegLkc6ie9p97Pjb4@vh5f3wvM@sFN5hcViZFcjxgiYGooTE1toTX1GhO2Xl@uHXgP5KXO5D/Mj/SnDhNE/9VgbE2FgEc6j/TKl8HVyvY8W2aRluiLShvTi3ndjS8EBxRDlvaFJNZitW9/YbfZpKm444r02E1Ao2kIrBbaUqmP8BdtP8LLhEAMam2ekX "Python 2 – Try It Online")
[Answer]
# C (tcc), ~~144~~ 136 bytes
```
a;f(s){char*t=s;for(;*t;a=!strncmp(s,"java",4))*t=tolower(*t++);for(t=s;*t;)s=strncmp(t++,"javascript",10)&&s;puts(a*s?"car":"carpet");}
```
[Try it online!](https://tio.run/##bZFBTwMhEIXv/RWVQwPbpdHEg5FsTOPB1IMxarxPkU3XdgFhWts0/e0r201TisuBhG/eG@aB5Chl04AoqWd7uQCXYeFFaRwVGQoorjw6LWtLfU6@YQMkv2UsaNCszK9yNMPxmB31rS9YmC9OllDqTF66yiLJb67ZaOSFXaOnkPkHIsGR@3a3CgkTh6bSOKyh0pQN9oNhWCXtrmUiPpbbBMwVaJ8wHuZQUP@j3TAJvUvAZI3VauIlaK1cKj5HOheep59T/v74Nnv9mL08nQrHqKQ9xQ16R@ggVxulMY5SglRzY5Y8EvmvZeLub/uzVm4XAbvDhdERcFve87wcbMXDn/LertpgamrDX2Q/NH8)
**Unrolled:**
```
a;
f(s)
{
    char *t = s;
    for (; *t; a = !strncmp(s, "java", 4))
        *t = tolower(*t++);
    for (t=s; *t;)
        s = strncmp(t++, "javascript", 10) && s;
    puts(a*s ? "car"  :"carpet");
}
```
[Answer]
# [JAISBaL](https://github.com/SocraticPhoenix/JAISBaL), 36 [bytes](https://github.com/SocraticPhoenix/JAISBaL/wiki/JAISBaL-Character-Encoding)
```
℠℘(?!.*javascript)^java.*}͵Ucar½Upet
```
Verbose/explanation:
```
# \# enable verbose parsing #\
tolower                           \# [0] convert the top value of the stack to lowercase #\
split (?!.*javascript)^java.*}    \# [1] split the top value of the stack by (?!.*javascript)^java.*} #\
arraylength                       \# [2] push the length of the array onto the stack #\
print3 car                        \# [3] print car #\
!if                               \# [4] if the top value on the stack is falsy, skip the next statement #\
print3 pet                        \# [5] print pet #\
```
JAISBaL was my first attempt at designing a golfing language, so it's rather quirky... there's no matches or contains, regex or otherwise, so instead we have to split and check the resulting array length... because JAISBaL has a split-by-regex... but no other regex support.... because reasons.
Regex ~~stolen~~ borrowed from [@Cows Quack's answer](https://codegolf.stackexchange.com/a/132276/56085).
[Answer]
# Excel, 84 bytes
```
="car"&IF(AND(ISERR(SEARCH("javascript",A1)),IFERROR(SEARCH("java",A1),2)=1),,"pet")
```
[Answer]
# Excel VBA, 76 Bytes
Anonymous VBE immediate window function that takes input from range `[A1]` and outputs is `car`/`carpet` status to the VBE immediate window
Does not use RegExp
```
?"car"IIf(InStr(1,[A1],"Java",1)*(InStr(1,[A1],"JavaScript",1)=0),"","pet")
```
[Answer]
# [Python 3](https://docs.python.org/3/), 95 bytes
```
g=lambda s:(lambda r:'car' if r[:4]=='java' and 'javascript' not in r else 'carpet')(s.lower())
```
[Try it online!](https://tio.run/##rdU9T8MwEAbgnV9xm@PBWWBAkTJUDBAGhACxIAYncVqnqW3Obml/faDhI6TqQn2ZvPjR@c6v43ZhYc1538/zTq7KWoLPku8VZqySyEA3gC/ZxWues1ZuJANpahiWvkLtAgNjA2gDCKrzCva7nAqMJz7t7LvChPPeoTYhmSdsoRnnEP@d/Yo3RVFQmKM4HJNcbLbx5lQslTQ@Ep2KwgdUchVlHopfl4RQvKTuY7oOukt9JY1ReCJ@UOOYjpNrHcXb2fNMPF49FPdPxd01hbiv8SemnKyPBKM@Kgq1USb46Mk0slKltUvxh/b18t/utMaWdNbt21rhjvKGu@GNpxRxK0ieyMPMOC0aiyKioaP4@U8iKXKawkkI@w8 "Python 3 – Try It Online")
Yeah, it could be shorter but I wanted to try using a nested lambda!
[Answer]
## [Perl](http://www.perl.org), **42 bytes**
I believe the answer by stevieb has an incorrect output (tried that one myself - it returns car for 'javajavascript'). This should work:
```
say/^java/i&&!/javascript/i?'car':'carpet'
```
[Answer]
# [Bracmat](https://github.com/BartJongejan/Bracmat), 66 bytes
```
(f=.pet:?b&@(low$!arg:(? javascript ?|java ?&:?b|?))&str$(car !b))
```
[Try it online!](https://tio.run/##TU/BbsIwDP2VgKouOSTnCQlliAOCw4TYtLuTJVCgSZa4DCT@vWvTCXqxn/Xes59VBF0Dti21cxEMzqQq3@jZ/xYTiPsZleQIF0g6VgGJvPcDkWWnukvGyoSxoBoimSjG2hpCQelc@AYLm/1M7A2@sDbb@mKvuSkDLmXEuxUG6n88nMn4lUz7LhqsziJpcM7E6UA9A20WXwv@sdytt5/r91VmuzTdG@PUT8jNxThMxII2yvsTH1Hp@5SVY@NPY@KNhBsevCPxyh9vcAgVtz6OFhDncRD0oR6Z/gA "Bracmat – Try It Online")
[Answer]
# [Go](https://go.dev), 134 bytes
```
import."strings"
func f(s string)string{T,o:=ToLower,"car"
if Contains(T(s),"javascript")||!HasPrefix(T(s),"java"){o+="pet"}
return o}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=jZHPSgMxEMbxOk8RA8IGNz2XQoVS_FMRKXXxVLDpNqmxbbIm2drS9upLeCmCL-FzeNGnMbupZREEL_mGmck3v2ReXsd6-56xdMLGHM2YVABylmnjaljMHH7LnaD1z-efnHVGqrHFIHKVIhFZFDIkyCqJdaOZ6Cv9xE2MU2YwSIHaWjlvbaMksiTGD2zObGpk5jBZrw8vmO0aLuSiUsZkpY-bOOMOb8BwlxuF9CbQfB18lNML2oigFYCfgxpNdCb5dGSjQWEAxSEWpQw5U7aMqMfkbLaLS4QQ10up5U5OazZlSnETCntUuGzdtuhNu9fpJp3r87Lq53rCAQF__gaouIeQ8jlXzoJgKR9qPaGVkh1Nys7qxcecmyVkS3evFZgF3b-KskxSoU3FAJR2oaGg3EN6Muj6vbipijClFLVbPeQVE_D30V1sC2rDlN998Yer0C0ifGT7ru-aJ8gHCsfIxsWyCYFNxbGvdp7d0-Qv2-Jn_mW7W-52G_Qb)
[Answer]
# [Lua](https://www.lua.org), 88 bytes
```
s=io.read():lower()print(s:sub(1,4)=='java'and not s:find'javascript'and'car'or'carpet')
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m704pzRxwYKlpSVpuhY3I4ptM_P1ilITUzQ0C4oy80o0iq1y8stTizQ0rYpLkzQMdUw0bW3VsxLLEtUT81IU8vJLFIqt0jLzUsBixclFmQUlIBn15MQi9fwiEFWQWqKuCTEfas2CJSDFEDYA)
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), ~~53~~ ~~49~~ 44 bytes
```
{32|}%"java"/(,\{6<"script"=+}/"carpet".3<if
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPn/v1rP0tDG2EhLu1ZVKSuxLFFJX0MnptrMRgmiQMlWu1ZfKTmxqCC1REnP2CYz7f9/L6Cy4OQirYISAA "GolfScript – Try It Online")
This was my second GolfScript submission so after writing a couple more I was able to revisit this and shave a couple bytes.
Previously, this mapped over a list, then summed it, then added it to a base value. Now, it just loops over the list, adding to the base value on each iteration.
Here's an explanation of how the code works:
```
{32|}%           # Convert the string to lowercase
"java"/          # Split on "java".
(,               # Extract the first item, and push its length
                 # (0 iff string starts with java).
\                # Swap so the rest of the list is on top of the stack.
{6<"script"=+}/  # Check if any start with "script":
{            }/  #   Loop over each item:
 6<              #     Take the first 6 characters.
   "script"=     #     Are they equal to "script"? (0 or 1)
            +    #     Add this to the top of the stack.
# After this loop, the stack will be 0 iff the string started
# with "java" and does not contain "javascript".
"carpet".3<     # Push "carpet" and its first 3 characters.
if              # If the value is 0, "car", otherwise "carpet".
```
[Answer]
# Mathematica, 82 bytes
regex
```
If[#~StringMatchQ~RegularExpression@"(?i)(?!.*javascript)^java.*","Car","Carpet"]&
```
[Answer]
## Batch, 91 bytes
```
@set/ps=
@set t=%s:~0,4%
@if "%t:java=%%s:javascript=%"=="%s%" (echo car)else echo carpet
```
Takes input on STDIN. Batch doesn't have a case insensitive comparison operator but it does have case insensitive string replacement so I can assign a temporary to the first four characters and then case insensitively replace java, which should then result in the empty string. Meanwhile I case insensitively replace javascript in the original string, which should leave it unchanged.
[Answer]
# Lua, 96 bytes
```
function(x)return x:lower():match"^java"and not x:lower():match"javascript"and"car"or"carpet"end
```
[Answer]
# Perl, ~~98~~ ~~84~~ 62 Bytes
```
sub a{"car".($_[0]=~/javascript/i||$_[0]!~/^java/i?'pet':'');}
```
[Try it online!](https://tio.run/##K0gtyjH9/7@4NEkhsVopObFISU9DJT7aINa2Tj8rsSyxOLkos6BEP7OmBiyqWKcfBxLWz7RXL0gtUbdSV9e0rv1fUJSZV6KQqKEEklMAExCNSprW/wE)
Thanks to bytepusher
[Answer]
# Dart VM, ~~104 bytes~~ 102 bytes
```
main(p){p=p[0].toLowerCase();print("car${p.indexOf('java')==0&&p.indexOf('javascript')<0?'':'pet'}");}
```
**Explanation**:
Degolfed:
```
main(p)
{
    p = p[0].toLowerCase();
    print("car${p.indexOf('java') == 0 && p.indexOf('javascript') < 0 ? '' : 'pet'}");
}
```
We have our usual main function
We replace `p` with `p[0].toLowerCase();` so that we don't have to declare a new variable (`var` plus a space would be 4 extra bytes)
We then proceed to do the actual printing
We print `car` unconditionally and we use inline statements for checking whether to print `pet` after it or not. If it has the string 'java' at index 0 and does not have 'javascript' in it, we do nothing (we actually append an empty string but it does not have any effect) and otherwise we append `pet`.
[Answer]
# Rust, 97 bytes
```
let s=if Regex::new(r"^javascript|^!java$").unwrap().is_match("javascript"){"carpet"}else{"car"};
```
I'm pretty sure that there is a shorter solution but it's my first try :)
]