MQTT subscription topic matchWrite the shortest code to match a tail-repeating string where one character falls off the head in each repetitionMatch strings with wildcardsPrint all 3 by 3 sturdy squaresMatch the Stack Exchange URLsMatch the permutations!All squares that match a wildcard sequenceMatch this random stringRegex: Match an egalitarian seriesMatch the Striking ClockMatch Roman Numerals

Why should I cook the flour first when making bechamel sauce?

What are the benefits to casting without the need for somatic components?

Is dividends exclusively a part of earnings?

Accidentally deleted python and yum is not working in centos7

A scene of Jimmy diversity

Can't update Ubuntu 18.04.2

What's the phrasal verb for carbonated drinks exploding out of the can after being shaken?

What are "full piece" and "half piece" in chess?

Animal Shelter Management C++

What made Windows ME so crash-prone?

When to ask for constructive criticism?

What is this old "lemon-squeezer" shaped pan

Is there any way for an Adventurers League, 5th level Wizard, to gain heavy armor proficiency?

Is this more than a packing puzzle?

Sending a photo of my bank account card to the future employer

What do these three diagonal lines that cross through three measures and both staves mean, and what are they called?

Why do the faithful have to say "And with your spirit " in Catholic Mass?

Why does the Earth have a z-component at the start of the J2000 epoch?

Draw a line nicely around notes

Did 007 exist before James Bond?

Do aircraft cabins have suspension?

Teferi's Time Twist on creature with +1/+1 counter

Does knowing a graph has a Hamiltonian Cycle make it easier to find the cycle?

What's the meaning of こそ in this sentence?



MQTT subscription topic match


Write the shortest code to match a tail-repeating string where one character falls off the head in each repetitionMatch strings with wildcardsPrint all 3 by 3 sturdy squaresMatch the Stack Exchange URLsMatch the permutations!All squares that match a wildcard sequenceMatch this random stringRegex: Match an egalitarian seriesMatch the Striking ClockMatch Roman Numerals






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6












$begingroup$


Background



MQTT (Message Queuing Telemetry Transport) is an ISO standard publish-subscribe-based messaging protocol (Wikipedia).



Each message has a topic, such as the following examples:



  • myhome/groundfloor/livingroom/temperature

  • USA/California/San Francisco/Silicon Valley

  • 5ff4a2ce-e485-40f4-826c-b1a5d81be9b6/status

  • Germany/Bavaria/car/2382340923453/latitude

MQTT clients may subscribe to message topics using wildcards:



  • Single level: +

  • All levels onward: #

For example, the subscription myhome/groundfloor/+/temperature would produce these results (non-conformances in bold):



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/temperature

❌ myhome/groundfloor/livingroom/brightness

❌ myhome/firstfloor/livingroom/temperature

garage/groundfloor/fridge/temperature



Whereas the subscription +/groundfloor/# would produce these results:



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/brightness

✅ garage/groundfloor/fridge/temperature/more/specific/fields

❌ myhome/firstfloor/livingroom/temperature

❌ myhome/basement/corner/temperature



More info here.



The Task



Implement a function/program accepting two strings and returning a boolean. The first string is the subject topic, the second is the criteria topic. The criteria topic uses the subscription syntax detailed above. The function is truthy when the subject matches the criteria.



Rules for this task:



  • Topics are ASCII

  • There are no criteria fields beyond the # wildcard

  • Wildcards do not appear in subject topics

  • Number of subject fields >= number of criteria fields

  • There are no 0-character fields nor leading or tailing forward slashes









share|improve this question











$endgroup$











  • $begingroup$
    @HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
    $endgroup$
    – Patrick
    8 hours ago






  • 3




    $begingroup$
    Are /, + and # guaranteed never to appear in topic parts?
    $endgroup$
    – Jonathan Allan
    7 hours ago










  • $begingroup$
    I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
    $endgroup$
    – Jonathan Allan
    7 hours ago







  • 1




    $begingroup$
    @JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
    $endgroup$
    – Nick Kennedy
    6 hours ago






  • 1




    $begingroup$
    @NickKennedy - nice digging, but we really shouldn't need to.
    $endgroup$
    – Jonathan Allan
    5 hours ago

















6












$begingroup$


Background



MQTT (Message Queuing Telemetry Transport) is an ISO standard publish-subscribe-based messaging protocol (Wikipedia).



Each message has a topic, such as the following examples:



  • myhome/groundfloor/livingroom/temperature

  • USA/California/San Francisco/Silicon Valley

  • 5ff4a2ce-e485-40f4-826c-b1a5d81be9b6/status

  • Germany/Bavaria/car/2382340923453/latitude

MQTT clients may subscribe to message topics using wildcards:



  • Single level: +

  • All levels onward: #

For example, the subscription myhome/groundfloor/+/temperature would produce these results (non-conformances in bold):



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/temperature

❌ myhome/groundfloor/livingroom/brightness

❌ myhome/firstfloor/livingroom/temperature

garage/groundfloor/fridge/temperature



Whereas the subscription +/groundfloor/# would produce these results:



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/brightness

✅ garage/groundfloor/fridge/temperature/more/specific/fields

❌ myhome/firstfloor/livingroom/temperature

❌ myhome/basement/corner/temperature



More info here.



The Task



Implement a function/program accepting two strings and returning a boolean. The first string is the subject topic, the second is the criteria topic. The criteria topic uses the subscription syntax detailed above. The function is truthy when the subject matches the criteria.



Rules for this task:



  • Topics are ASCII

  • There are no criteria fields beyond the # wildcard

  • Wildcards do not appear in subject topics

  • Number of subject fields >= number of criteria fields

  • There are no 0-character fields nor leading or tailing forward slashes









share|improve this question











$endgroup$











  • $begingroup$
    @HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
    $endgroup$
    – Patrick
    8 hours ago






  • 3




    $begingroup$
    Are /, + and # guaranteed never to appear in topic parts?
    $endgroup$
    – Jonathan Allan
    7 hours ago










  • $begingroup$
    I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
    $endgroup$
    – Jonathan Allan
    7 hours ago







  • 1




    $begingroup$
    @JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
    $endgroup$
    – Nick Kennedy
    6 hours ago






  • 1




    $begingroup$
    @NickKennedy - nice digging, but we really shouldn't need to.
    $endgroup$
    – Jonathan Allan
    5 hours ago













6












6








6





$begingroup$


Background



MQTT (Message Queuing Telemetry Transport) is an ISO standard publish-subscribe-based messaging protocol (Wikipedia).



Each message has a topic, such as the following examples:



  • myhome/groundfloor/livingroom/temperature

  • USA/California/San Francisco/Silicon Valley

  • 5ff4a2ce-e485-40f4-826c-b1a5d81be9b6/status

  • Germany/Bavaria/car/2382340923453/latitude

MQTT clients may subscribe to message topics using wildcards:



  • Single level: +

  • All levels onward: #

For example, the subscription myhome/groundfloor/+/temperature would produce these results (non-conformances in bold):



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/temperature

❌ myhome/groundfloor/livingroom/brightness

❌ myhome/firstfloor/livingroom/temperature

garage/groundfloor/fridge/temperature



Whereas the subscription +/groundfloor/# would produce these results:



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/brightness

✅ garage/groundfloor/fridge/temperature/more/specific/fields

❌ myhome/firstfloor/livingroom/temperature

❌ myhome/basement/corner/temperature



More info here.



The Task



Implement a function/program accepting two strings and returning a boolean. The first string is the subject topic, the second is the criteria topic. The criteria topic uses the subscription syntax detailed above. The function is truthy when the subject matches the criteria.



Rules for this task:



  • Topics are ASCII

  • There are no criteria fields beyond the # wildcard

  • Wildcards do not appear in subject topics

  • Number of subject fields >= number of criteria fields

  • There are no 0-character fields nor leading or tailing forward slashes









share|improve this question











$endgroup$




Background



MQTT (Message Queuing Telemetry Transport) is an ISO standard publish-subscribe-based messaging protocol (Wikipedia).



Each message has a topic, such as the following examples:



  • myhome/groundfloor/livingroom/temperature

  • USA/California/San Francisco/Silicon Valley

  • 5ff4a2ce-e485-40f4-826c-b1a5d81be9b6/status

  • Germany/Bavaria/car/2382340923453/latitude

MQTT clients may subscribe to message topics using wildcards:



  • Single level: +

  • All levels onward: #

For example, the subscription myhome/groundfloor/+/temperature would produce these results (non-conformances in bold):



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/temperature

❌ myhome/groundfloor/livingroom/brightness

❌ myhome/firstfloor/livingroom/temperature

garage/groundfloor/fridge/temperature



Whereas the subscription +/groundfloor/# would produce these results:



✅ myhome/groundfloor/livingroom/temperature

✅ myhome/groundfloor/kitchen/brightness

✅ garage/groundfloor/fridge/temperature/more/specific/fields

❌ myhome/firstfloor/livingroom/temperature

❌ myhome/basement/corner/temperature



More info here.



The Task



Implement a function/program accepting two strings and returning a boolean. The first string is the subject topic, the second is the criteria topic. The criteria topic uses the subscription syntax detailed above. The function is truthy when the subject matches the criteria.



Rules for this task:



  • Topics are ASCII

  • There are no criteria fields beyond the # wildcard

  • Wildcards do not appear in subject topics

  • Number of subject fields >= number of criteria fields

  • There are no 0-character fields nor leading or tailing forward slashes






code-golf string decision-problem parsing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 1 hour ago









Jonathan Allan

57.5k5 gold badges43 silver badges181 bronze badges




57.5k5 gold badges43 silver badges181 bronze badges










asked 8 hours ago









PatrickPatrick

1814 bronze badges




1814 bronze badges











  • $begingroup$
    @HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
    $endgroup$
    – Patrick
    8 hours ago






  • 3




    $begingroup$
    Are /, + and # guaranteed never to appear in topic parts?
    $endgroup$
    – Jonathan Allan
    7 hours ago










  • $begingroup$
    I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
    $endgroup$
    – Jonathan Allan
    7 hours ago







  • 1




    $begingroup$
    @JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
    $endgroup$
    – Nick Kennedy
    6 hours ago






  • 1




    $begingroup$
    @NickKennedy - nice digging, but we really shouldn't need to.
    $endgroup$
    – Jonathan Allan
    5 hours ago
















  • $begingroup$
    @HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
    $endgroup$
    – Patrick
    8 hours ago






  • 3




    $begingroup$
    Are /, + and # guaranteed never to appear in topic parts?
    $endgroup$
    – Jonathan Allan
    7 hours ago










  • $begingroup$
    I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
    $endgroup$
    – Jonathan Allan
    7 hours ago







  • 1




    $begingroup$
    @JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
    $endgroup$
    – Nick Kennedy
    6 hours ago






  • 1




    $begingroup$
    @NickKennedy - nice digging, but we really shouldn't need to.
    $endgroup$
    – Jonathan Allan
    5 hours ago















$begingroup$
@HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
$endgroup$
– Patrick
8 hours ago




$begingroup$
@HyperNeutrino, that's a good question. I'm on the fence. Subject a/b/c would not match criteria a/b, so I'm inclined to say No.
$endgroup$
– Patrick
8 hours ago




3




3




$begingroup$
Are /, + and # guaranteed never to appear in topic parts?
$endgroup$
– Jonathan Allan
7 hours ago




$begingroup$
Are /, + and # guaranteed never to appear in topic parts?
$endgroup$
– Jonathan Allan
7 hours ago












$begingroup$
I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
$endgroup$
– Jonathan Allan
7 hours ago





$begingroup$
I see in the blog linked that "Additionally, the forward slash alone is a valid topic" but no mention of + and #, so I guess these two can be.
$endgroup$
– Jonathan Allan
7 hours ago





1




1




$begingroup$
@JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
$endgroup$
– Nick Kennedy
6 hours ago




$begingroup$
@JonathanAllan From docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/… : The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name
$endgroup$
– Nick Kennedy
6 hours ago




1




1




$begingroup$
@NickKennedy - nice digging, but we really shouldn't need to.
$endgroup$
– Jonathan Allan
5 hours ago




$begingroup$
@NickKennedy - nice digging, but we really shouldn't need to.
$endgroup$
– Jonathan Allan
5 hours ago










9 Answers
9






active

oldest

votes


















1












$begingroup$


Python 2, 85 84 80 92 89 bytes





lambda s,c:all(x in('+','#',y)for x,y in zip(c.split('/')+[0]*-c.find('#'),s.split('/')))


Try it online!



Thanks to Jonathan Allan and Value Ink for pointing out bugs.






share|improve this answer











$endgroup$












  • $begingroup$
    Gives the wrong answer on f('ab', 'abc').
    $endgroup$
    – Value Ink
    2 hours ago










  • $begingroup$
    @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
    $endgroup$
    – Chas Brown
    2 hours ago










  • $begingroup$
    Oh weird rule given the problem context!
    $endgroup$
    – Jonathan Allan
    2 hours ago


















1












$begingroup$


Jelly, 20 bytes



ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE


A monadic Link accepting a list of lists of characters, [topic, pattern], which returns 1 or 0 for match or no-match respectively.



Try it online! Or see a test-suite.



How?



ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE - Link: list of lists of characters, [topic, pattern]
€ - for each:
ṣ - split at occurrences of:
”/ - '/' character
Z - transpose (any excess of topic is kept)
¿ - while...
Ɗ - ...condition: last three links as a monad:
”# - '#' character
e - exists in:
F - flatten
Ṗ - ...do: pop the tail off
Ðḟ - filter discard those for which:
œi - first multi-dimensional index of: ([] if not found, which is falsey)
”+ - '+' character
Z - transpose
E - all equal?





share|improve this answer











$endgroup$




















    0












    $begingroup$


    Python 3, 72 bytes





    lambda a,b:bool(re.match(b.translate(43:"[^/]+",35:".+"),a))
    import re


    Try it online!



    This problem can be trivially simplified to a regex match, though another more interesting method may produce better results.



    EDIT I came up with a 107-byte solution not using regex. I don't know if it can get shorter than 72 or maybe I'm just not seeing to correct approach to this. Just the split-zip structure seems to be too large though. Try It Online!






    share|improve this answer









    $endgroup$








    • 2




      $begingroup$
      If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
      $endgroup$
      – Value Ink
      4 hours ago










    • $begingroup$
      ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
      $endgroup$
      – Jonathan Allan
      3 hours ago










    • $begingroup$
      As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
      $endgroup$
      – Chas Brown
      3 hours ago


















    0












    $begingroup$


    Ruby, 65 bytes



    Regex solution. I added Regex.escape in case a criteria name just so happens to be something like com.java/string[]/n or something silly that would have regex pieces.





    ->s,cs=~/^#Regexp.escape(c).sub('#','.*').gsub'+','[^/]*'$/


    Try it online!



    Non-regex solution, 77 bytes



    Uses a nice simple split, zip, and match technique. I developed this one first before realizing that even with Regex.escape the regex solution would've been shorter anyways.



    ->s,cs.split(?/).zip(c.split ?/).all?i,j


    Try it online!






    share|improve this answer









    $endgroup$




















      0












      $begingroup$


      Kotlin, 106 bytes



      fun f(s:List<String>)=s[1].split("/").filterIndexedi,v->v!="+"&&v!="#"&&v!=s[0].split("/")[i].count()==0


      Try it online!






      share|improve this answer









      $endgroup$




















        0












        $begingroup$


        Jelly, 22 bytes



        ṣ€”/Zn”+Ȧ$Ƈ“#”eⱮœpƊḢZE


        Try it online!



        A monadic link that takes as its argument [criterion], [topic] and returns 1 for a match and 0 for no match.






        share|improve this answer









        $endgroup$




















          0












          $begingroup$

          Haskell, 76 73 71 bytes



          (a:b)#(c:d)=a=='+'&&b#snd(span(/='/')d)||a=='#'||a==c&&b#d
          a#b=a++b==[]


          Try it online!






          share|improve this answer











          $endgroup$




















            0












            $begingroup$

            Python 3, 99 88 bytes



            Without using a regex. With some help from Jonathan Allan.



            f=lambda s,p:p in(s,'#')or p[:1]in(s[:1],'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])


            previous answer:



            f=lambda s,p:s==p or'#'==p[0]or s[0]==p[0]and f(s[1:],p[1:])or'+'==p[0]and f(s[1:],p[2*(s[0]=='/'):])





            share|improve this answer











            $endgroup$












            • $begingroup$
              f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
              $endgroup$
              – Jonathan Allan
              3 hours ago










            • $begingroup$
              This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
              $endgroup$
              – Chas Brown
              1 hour ago











            • $begingroup$
              ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
              $endgroup$
              – Jonathan Allan
              1 hour ago











            • $begingroup$
              Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
              $endgroup$
              – Jonathan Allan
              45 mins ago










            • $begingroup$
              Try it online is always recommended!
              $endgroup$
              – Chas Brown
              44 mins ago


















            0












            $begingroup$


            Clojure, 107 91 76 65 72 102 bytes



            An anonymous function, returns subject topic as truthy and nil as falsey (valid in Clojure).



            (defn ?[t c](every? #(#"#""+"(% 0)(% 1))(apply #(map vector % %2)(map #(re-seq #"[^/]+" %) [t c]))))


            107 102 working
            91 76 65 all defeated with regex chars






            share|improve this answer











            $endgroup$












            • $begingroup$
              ...and my comment under your question becomes pertinent
              $endgroup$
              – Jonathan Allan
              7 hours ago











            • $begingroup$
              @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
              $endgroup$
              – Patrick
              2 hours ago










            • $begingroup$
              I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
              $endgroup$
              – Chas Brown
              1 hour ago










            • $begingroup$
              @ChasBrown, correct, and with ^ instead of $; thanks.
              $endgroup$
              – Patrick
              1 hour ago






            • 1




              $begingroup$
              Try with 'Q' before and 'E' after the pattern prior to the replace - source
              $endgroup$
              – Jonathan Allan
              1 hour ago













            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "200"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188397%2fmqtt-subscription-topic-match%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1












            $begingroup$


            Python 2, 85 84 80 92 89 bytes





            lambda s,c:all(x in('+','#',y)for x,y in zip(c.split('/')+[0]*-c.find('#'),s.split('/')))


            Try it online!



            Thanks to Jonathan Allan and Value Ink for pointing out bugs.






            share|improve this answer











            $endgroup$












            • $begingroup$
              Gives the wrong answer on f('ab', 'abc').
              $endgroup$
              – Value Ink
              2 hours ago










            • $begingroup$
              @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
              $endgroup$
              – Chas Brown
              2 hours ago










            • $begingroup$
              Oh weird rule given the problem context!
              $endgroup$
              – Jonathan Allan
              2 hours ago















            1












            $begingroup$


            Python 2, 85 84 80 92 89 bytes





            lambda s,c:all(x in('+','#',y)for x,y in zip(c.split('/')+[0]*-c.find('#'),s.split('/')))


            Try it online!



            Thanks to Jonathan Allan and Value Ink for pointing out bugs.






            share|improve this answer











            $endgroup$












            • $begingroup$
              Gives the wrong answer on f('ab', 'abc').
              $endgroup$
              – Value Ink
              2 hours ago










            • $begingroup$
              @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
              $endgroup$
              – Chas Brown
              2 hours ago










            • $begingroup$
              Oh weird rule given the problem context!
              $endgroup$
              – Jonathan Allan
              2 hours ago













            1












            1








            1





            $begingroup$


            Python 2, 85 84 80 92 89 bytes





            lambda s,c:all(x in('+','#',y)for x,y in zip(c.split('/')+[0]*-c.find('#'),s.split('/')))


            Try it online!



            Thanks to Jonathan Allan and Value Ink for pointing out bugs.






            share|improve this answer











            $endgroup$




            Python 2, 85 84 80 92 89 bytes





            lambda s,c:all(x in('+','#',y)for x,y in zip(c.split('/')+[0]*-c.find('#'),s.split('/')))


            Try it online!



            Thanks to Jonathan Allan and Value Ink for pointing out bugs.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited 2 hours ago

























            answered 3 hours ago









            Chas BrownChas Brown

            5,8391 gold badge6 silver badges23 bronze badges




            5,8391 gold badge6 silver badges23 bronze badges











            • $begingroup$
              Gives the wrong answer on f('ab', 'abc').
              $endgroup$
              – Value Ink
              2 hours ago










            • $begingroup$
              @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
              $endgroup$
              – Chas Brown
              2 hours ago










            • $begingroup$
              Oh weird rule given the problem context!
              $endgroup$
              – Jonathan Allan
              2 hours ago
















            • $begingroup$
              Gives the wrong answer on f('ab', 'abc').
              $endgroup$
              – Value Ink
              2 hours ago










            • $begingroup$
              @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
              $endgroup$
              – Chas Brown
              2 hours ago










            • $begingroup$
              Oh weird rule given the problem context!
              $endgroup$
              – Jonathan Allan
              2 hours ago















            $begingroup$
            Gives the wrong answer on f('ab', 'abc').
            $endgroup$
            – Value Ink
            2 hours ago




            $begingroup$
            Gives the wrong answer on f('ab', 'abc').
            $endgroup$
            – Value Ink
            2 hours ago












            $begingroup$
            @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
            $endgroup$
            – Chas Brown
            2 hours ago




            $begingroup$
            @Jonathan Allan: Actually, rules say 'Number of subject fields >= number of criteria fields'. But other problems needed fixing...
            $endgroup$
            – Chas Brown
            2 hours ago












            $begingroup$
            Oh weird rule given the problem context!
            $endgroup$
            – Jonathan Allan
            2 hours ago




            $begingroup$
            Oh weird rule given the problem context!
            $endgroup$
            – Jonathan Allan
            2 hours ago













            1












            $begingroup$


            Jelly, 20 bytes



            ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE


            A monadic Link accepting a list of lists of characters, [topic, pattern], which returns 1 or 0 for match or no-match respectively.



            Try it online! Or see a test-suite.



            How?



            ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE - Link: list of lists of characters, [topic, pattern]
            € - for each:
            ṣ - split at occurrences of:
            ”/ - '/' character
            Z - transpose (any excess of topic is kept)
            ¿ - while...
            Ɗ - ...condition: last three links as a monad:
            ”# - '#' character
            e - exists in:
            F - flatten
            Ṗ - ...do: pop the tail off
            Ðḟ - filter discard those for which:
            œi - first multi-dimensional index of: ([] if not found, which is falsey)
            ”+ - '+' character
            Z - transpose
            E - all equal?





            share|improve this answer











            $endgroup$

















              1












              $begingroup$


              Jelly, 20 bytes



              ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE


              A monadic Link accepting a list of lists of characters, [topic, pattern], which returns 1 or 0 for match or no-match respectively.



              Try it online! Or see a test-suite.



              How?



              ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE - Link: list of lists of characters, [topic, pattern]
              € - for each:
              ṣ - split at occurrences of:
              ”/ - '/' character
              Z - transpose (any excess of topic is kept)
              ¿ - while...
              Ɗ - ...condition: last three links as a monad:
              ”# - '#' character
              e - exists in:
              F - flatten
              Ṗ - ...do: pop the tail off
              Ðḟ - filter discard those for which:
              œi - first multi-dimensional index of: ([] if not found, which is falsey)
              ”+ - '+' character
              Z - transpose
              E - all equal?





              share|improve this answer











              $endgroup$















                1












                1








                1





                $begingroup$


                Jelly, 20 bytes



                ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE


                A monadic Link accepting a list of lists of characters, [topic, pattern], which returns 1 or 0 for match or no-match respectively.



                Try it online! Or see a test-suite.



                How?



                ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE - Link: list of lists of characters, [topic, pattern]
                € - for each:
                ṣ - split at occurrences of:
                ”/ - '/' character
                Z - transpose (any excess of topic is kept)
                ¿ - while...
                Ɗ - ...condition: last three links as a monad:
                ”# - '#' character
                e - exists in:
                F - flatten
                Ṗ - ...do: pop the tail off
                Ðḟ - filter discard those for which:
                œi - first multi-dimensional index of: ([] if not found, which is falsey)
                ”+ - '+' character
                Z - transpose
                E - all equal?





                share|improve this answer











                $endgroup$




                Jelly, 20 bytes



                ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE


                A monadic Link accepting a list of lists of characters, [topic, pattern], which returns 1 or 0 for match or no-match respectively.



                Try it online! Or see a test-suite.



                How?



                ṣ€”/ZṖF”#eƊ¿œiÐḟ”+ZE - Link: list of lists of characters, [topic, pattern]
                € - for each:
                ṣ - split at occurrences of:
                ”/ - '/' character
                Z - transpose (any excess of topic is kept)
                ¿ - while...
                Ɗ - ...condition: last three links as a monad:
                ”# - '#' character
                e - exists in:
                F - flatten
                Ṗ - ...do: pop the tail off
                Ðḟ - filter discard those for which:
                œi - first multi-dimensional index of: ([] if not found, which is falsey)
                ”+ - '+' character
                Z - transpose
                E - all equal?






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 1 hour ago









                Jonathan AllanJonathan Allan

                57.5k5 gold badges43 silver badges181 bronze badges




                57.5k5 gold badges43 silver badges181 bronze badges





















                    0












                    $begingroup$


                    Python 3, 72 bytes





                    lambda a,b:bool(re.match(b.translate(43:"[^/]+",35:".+"),a))
                    import re


                    Try it online!



                    This problem can be trivially simplified to a regex match, though another more interesting method may produce better results.



                    EDIT I came up with a 107-byte solution not using regex. I don't know if it can get shorter than 72 or maybe I'm just not seeing to correct approach to this. Just the split-zip structure seems to be too large though. Try It Online!






                    share|improve this answer









                    $endgroup$








                    • 2




                      $begingroup$
                      If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                      $endgroup$
                      – Value Ink
                      4 hours ago










                    • $begingroup$
                      ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                      $endgroup$
                      – Jonathan Allan
                      3 hours ago










                    • $begingroup$
                      As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                      $endgroup$
                      – Chas Brown
                      3 hours ago















                    0












                    $begingroup$


                    Python 3, 72 bytes





                    lambda a,b:bool(re.match(b.translate(43:"[^/]+",35:".+"),a))
                    import re


                    Try it online!



                    This problem can be trivially simplified to a regex match, though another more interesting method may produce better results.



                    EDIT I came up with a 107-byte solution not using regex. I don't know if it can get shorter than 72 or maybe I'm just not seeing to correct approach to this. Just the split-zip structure seems to be too large though. Try It Online!






                    share|improve this answer









                    $endgroup$








                    • 2




                      $begingroup$
                      If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                      $endgroup$
                      – Value Ink
                      4 hours ago










                    • $begingroup$
                      ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                      $endgroup$
                      – Jonathan Allan
                      3 hours ago










                    • $begingroup$
                      As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                      $endgroup$
                      – Chas Brown
                      3 hours ago













                    0












                    0








                    0





                    $begingroup$


                    Python 3, 72 bytes





                    lambda a,b:bool(re.match(b.translate(43:"[^/]+",35:".+"),a))
                    import re


                    Try it online!



                    This problem can be trivially simplified to a regex match, though another more interesting method may produce better results.



                    EDIT I came up with a 107-byte solution not using regex. I don't know if it can get shorter than 72 or maybe I'm just not seeing to correct approach to this. Just the split-zip structure seems to be too large though. Try It Online!






                    share|improve this answer









                    $endgroup$




                    Python 3, 72 bytes





                    lambda a,b:bool(re.match(b.translate(43:"[^/]+",35:".+"),a))
                    import re


                    Try it online!



                    This problem can be trivially simplified to a regex match, though another more interesting method may produce better results.



                    EDIT I came up with a 107-byte solution not using regex. I don't know if it can get shorter than 72 or maybe I'm just not seeing to correct approach to this. Just the split-zip structure seems to be too large though. Try It Online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 8 hours ago









                    HyperNeutrinoHyperNeutrino

                    20.4k4 gold badges41 silver badges153 bronze badges




                    20.4k4 gold badges41 silver badges153 bronze badges







                    • 2




                      $begingroup$
                      If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                      $endgroup$
                      – Value Ink
                      4 hours ago










                    • $begingroup$
                      ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                      $endgroup$
                      – Jonathan Allan
                      3 hours ago










                    • $begingroup$
                      As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                      $endgroup$
                      – Chas Brown
                      3 hours ago












                    • 2




                      $begingroup$
                      If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                      $endgroup$
                      – Value Ink
                      4 hours ago










                    • $begingroup$
                      ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                      $endgroup$
                      – Jonathan Allan
                      3 hours ago










                    • $begingroup$
                      As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                      $endgroup$
                      – Chas Brown
                      3 hours ago







                    2




                    2




                    $begingroup$
                    If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                    $endgroup$
                    – Value Ink
                    4 hours ago




                    $begingroup$
                    If the sequence contains any other regex characters, this might fail. I'd look out for that even though none of the current test cases contain anything remotely regex-like.
                    $endgroup$
                    – Value Ink
                    4 hours ago












                    $begingroup$
                    ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                    $endgroup$
                    – Jonathan Allan
                    3 hours ago




                    $begingroup$
                    ...like f('myhome/ground$floor/livingroom/temperature', 'myhome/ground$floor/+/temperature') which fails
                    $endgroup$
                    – Jonathan Allan
                    3 hours ago












                    $begingroup$
                    As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                    $endgroup$
                    – Chas Brown
                    3 hours ago




                    $begingroup$
                    As Value Ink says, +/kei$ha/+ does not match music/kei$ha/latest.
                    $endgroup$
                    – Chas Brown
                    3 hours ago











                    0












                    $begingroup$


                    Ruby, 65 bytes



                    Regex solution. I added Regex.escape in case a criteria name just so happens to be something like com.java/string[]/n or something silly that would have regex pieces.





                    ->s,cs=~/^#Regexp.escape(c).sub('#','.*').gsub'+','[^/]*'$/


                    Try it online!



                    Non-regex solution, 77 bytes



                    Uses a nice simple split, zip, and match technique. I developed this one first before realizing that even with Regex.escape the regex solution would've been shorter anyways.



                    ->s,cs.split(?/).zip(c.split ?/).all?i,j


                    Try it online!






                    share|improve this answer









                    $endgroup$

















                      0












                      $begingroup$


                      Ruby, 65 bytes



                      Regex solution. I added Regex.escape in case a criteria name just so happens to be something like com.java/string[]/n or something silly that would have regex pieces.





                      ->s,cs=~/^#Regexp.escape(c).sub('#','.*').gsub'+','[^/]*'$/


                      Try it online!



                      Non-regex solution, 77 bytes



                      Uses a nice simple split, zip, and match technique. I developed this one first before realizing that even with Regex.escape the regex solution would've been shorter anyways.



                      ->s,cs.split(?/).zip(c.split ?/).all?i,j


                      Try it online!






                      share|improve this answer









                      $endgroup$















                        0












                        0








                        0





                        $begingroup$


                        Ruby, 65 bytes



                        Regex solution. I added Regex.escape in case a criteria name just so happens to be something like com.java/string[]/n or something silly that would have regex pieces.





                        ->s,cs=~/^#Regexp.escape(c).sub('#','.*').gsub'+','[^/]*'$/


                        Try it online!



                        Non-regex solution, 77 bytes



                        Uses a nice simple split, zip, and match technique. I developed this one first before realizing that even with Regex.escape the regex solution would've been shorter anyways.



                        ->s,cs.split(?/).zip(c.split ?/).all?i,j


                        Try it online!






                        share|improve this answer









                        $endgroup$




                        Ruby, 65 bytes



                        Regex solution. I added Regex.escape in case a criteria name just so happens to be something like com.java/string[]/n or something silly that would have regex pieces.





                        ->s,cs=~/^#Regexp.escape(c).sub('#','.*').gsub'+','[^/]*'$/


                        Try it online!



                        Non-regex solution, 77 bytes



                        Uses a nice simple split, zip, and match technique. I developed this one first before realizing that even with Regex.escape the regex solution would've been shorter anyways.



                        ->s,cs.split(?/).zip(c.split ?/).all?i,j


                        Try it online!







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered 3 hours ago









                        Value InkValue Ink

                        8,8757 silver badges32 bronze badges




                        8,8757 silver badges32 bronze badges





















                            0












                            $begingroup$


                            Kotlin, 106 bytes



                            fun f(s:List<String>)=s[1].split("/").filterIndexedi,v->v!="+"&&v!="#"&&v!=s[0].split("/")[i].count()==0


                            Try it online!






                            share|improve this answer









                            $endgroup$

















                              0












                              $begingroup$


                              Kotlin, 106 bytes



                              fun f(s:List<String>)=s[1].split("/").filterIndexedi,v->v!="+"&&v!="#"&&v!=s[0].split("/")[i].count()==0


                              Try it online!






                              share|improve this answer









                              $endgroup$















                                0












                                0








                                0





                                $begingroup$


                                Kotlin, 106 bytes



                                fun f(s:List<String>)=s[1].split("/").filterIndexedi,v->v!="+"&&v!="#"&&v!=s[0].split("/")[i].count()==0


                                Try it online!






                                share|improve this answer









                                $endgroup$




                                Kotlin, 106 bytes



                                fun f(s:List<String>)=s[1].split("/").filterIndexedi,v->v!="+"&&v!="#"&&v!=s[0].split("/")[i].count()==0


                                Try it online!







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered 3 hours ago









                                QuinnQuinn

                                44310 bronze badges




                                44310 bronze badges





















                                    0












                                    $begingroup$


                                    Jelly, 22 bytes



                                    ṣ€”/Zn”+Ȧ$Ƈ“#”eⱮœpƊḢZE


                                    Try it online!



                                    A monadic link that takes as its argument [criterion], [topic] and returns 1 for a match and 0 for no match.






                                    share|improve this answer









                                    $endgroup$

















                                      0












                                      $begingroup$


                                      Jelly, 22 bytes



                                      ṣ€”/Zn”+Ȧ$Ƈ“#”eⱮœpƊḢZE


                                      Try it online!



                                      A monadic link that takes as its argument [criterion], [topic] and returns 1 for a match and 0 for no match.






                                      share|improve this answer









                                      $endgroup$















                                        0












                                        0








                                        0





                                        $begingroup$


                                        Jelly, 22 bytes



                                        ṣ€”/Zn”+Ȧ$Ƈ“#”eⱮœpƊḢZE


                                        Try it online!



                                        A monadic link that takes as its argument [criterion], [topic] and returns 1 for a match and 0 for no match.






                                        share|improve this answer









                                        $endgroup$




                                        Jelly, 22 bytes



                                        ṣ€”/Zn”+Ȧ$Ƈ“#”eⱮœpƊḢZE


                                        Try it online!



                                        A monadic link that takes as its argument [criterion], [topic] and returns 1 for a match and 0 for no match.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered 2 hours ago









                                        Nick KennedyNick Kennedy

                                        4,6848 silver badges14 bronze badges




                                        4,6848 silver badges14 bronze badges





















                                            0












                                            $begingroup$

                                            Haskell, 76 73 71 bytes



                                            (a:b)#(c:d)=a=='+'&&b#snd(span(/='/')d)||a=='#'||a==c&&b#d
                                            a#b=a++b==[]


                                            Try it online!






                                            share|improve this answer











                                            $endgroup$

















                                              0












                                              $begingroup$

                                              Haskell, 76 73 71 bytes



                                              (a:b)#(c:d)=a=='+'&&b#snd(span(/='/')d)||a=='#'||a==c&&b#d
                                              a#b=a++b==[]


                                              Try it online!






                                              share|improve this answer











                                              $endgroup$















                                                0












                                                0








                                                0





                                                $begingroup$

                                                Haskell, 76 73 71 bytes



                                                (a:b)#(c:d)=a=='+'&&b#snd(span(/='/')d)||a=='#'||a==c&&b#d
                                                a#b=a++b==[]


                                                Try it online!






                                                share|improve this answer











                                                $endgroup$



                                                Haskell, 76 73 71 bytes



                                                (a:b)#(c:d)=a=='+'&&b#snd(span(/='/')d)||a=='#'||a==c&&b#d
                                                a#b=a++b==[]


                                                Try it online!







                                                share|improve this answer














                                                share|improve this answer



                                                share|improve this answer








                                                edited 1 hour ago

























                                                answered 3 hours ago









                                                niminimi

                                                33.5k3 gold badges26 silver badges91 bronze badges




                                                33.5k3 gold badges26 silver badges91 bronze badges





















                                                    0












                                                    $begingroup$

                                                    Python 3, 99 88 bytes



                                                    Without using a regex. With some help from Jonathan Allan.



                                                    f=lambda s,p:p in(s,'#')or p[:1]in(s[:1],'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])


                                                    previous answer:



                                                    f=lambda s,p:s==p or'#'==p[0]or s[0]==p[0]and f(s[1:],p[1:])or'+'==p[0]and f(s[1:],p[2*(s[0]=='/'):])





                                                    share|improve this answer











                                                    $endgroup$












                                                    • $begingroup$
                                                      f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      3 hours ago










                                                    • $begingroup$
                                                      This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago











                                                    • $begingroup$
                                                      ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago











                                                    • $begingroup$
                                                      Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      45 mins ago










                                                    • $begingroup$
                                                      Try it online is always recommended!
                                                      $endgroup$
                                                      – Chas Brown
                                                      44 mins ago















                                                    0












                                                    $begingroup$

                                                    Python 3, 99 88 bytes



                                                    Without using a regex. With some help from Jonathan Allan.



                                                    f=lambda s,p:p in(s,'#')or p[:1]in(s[:1],'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])


                                                    previous answer:



                                                    f=lambda s,p:s==p or'#'==p[0]or s[0]==p[0]and f(s[1:],p[1:])or'+'==p[0]and f(s[1:],p[2*(s[0]=='/'):])





                                                    share|improve this answer











                                                    $endgroup$












                                                    • $begingroup$
                                                      f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      3 hours ago










                                                    • $begingroup$
                                                      This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago











                                                    • $begingroup$
                                                      ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago











                                                    • $begingroup$
                                                      Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      45 mins ago










                                                    • $begingroup$
                                                      Try it online is always recommended!
                                                      $endgroup$
                                                      – Chas Brown
                                                      44 mins ago













                                                    0












                                                    0








                                                    0





                                                    $begingroup$

                                                    Python 3, 99 88 bytes



                                                    Without using a regex. With some help from Jonathan Allan.



                                                    f=lambda s,p:p in(s,'#')or p[:1]in(s[:1],'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])


                                                    previous answer:



                                                    f=lambda s,p:s==p or'#'==p[0]or s[0]==p[0]and f(s[1:],p[1:])or'+'==p[0]and f(s[1:],p[2*(s[0]=='/'):])





                                                    share|improve this answer











                                                    $endgroup$



                                                    Python 3, 99 88 bytes



                                                    Without using a regex. With some help from Jonathan Allan.



                                                    f=lambda s,p:p in(s,'#')or p[:1]in(s[:1],'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])


                                                    previous answer:



                                                    f=lambda s,p:s==p or'#'==p[0]or s[0]==p[0]and f(s[1:],p[1:])or'+'==p[0]and f(s[1:],p[2*(s[0]=='/'):])






                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited 1 hour ago

























                                                    answered 4 hours ago









                                                    RootTwoRootTwo

                                                    1,7293 silver badges6 bronze badges




                                                    1,7293 silver badges6 bronze badges











                                                    • $begingroup$
                                                      f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      3 hours ago










                                                    • $begingroup$
                                                      This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago











                                                    • $begingroup$
                                                      ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago











                                                    • $begingroup$
                                                      Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      45 mins ago










                                                    • $begingroup$
                                                      Try it online is always recommended!
                                                      $endgroup$
                                                      – Chas Brown
                                                      44 mins ago
















                                                    • $begingroup$
                                                      f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      3 hours ago










                                                    • $begingroup$
                                                      This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago











                                                    • $begingroup$
                                                      ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago











                                                    • $begingroup$
                                                      Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      45 mins ago










                                                    • $begingroup$
                                                      Try it online is always recommended!
                                                      $endgroup$
                                                      – Chas Brown
                                                      44 mins ago















                                                    $begingroup$
                                                    f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    3 hours ago




                                                    $begingroup$
                                                    f=lambda s,p:s==p or'#'==p[0]or p[0]in(s[0]+'+')and f(s[1:],p['+'!=p[0]or(s[0]=='/')*2:]) saves 12. However this fails to process some edge cases like f('abc/ijk/x', 'abc/+/xyz') or f('abc/ijk/xyz', 'abc/+/x'), which can be fixed with f=lambda s,p:s==p or'#'==p[:1]or p[:1]in(s[:1]+'+')and f(s[1:],p['+'!=p[:1]or(s[:1]=='/')*2:])
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    3 hours ago












                                                    $begingroup$
                                                    This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                    $endgroup$
                                                    – Chas Brown
                                                    1 hour ago





                                                    $begingroup$
                                                    This fails for f('abc','ab') and f('abc/de','abc') (both should return False, but instead there's an IndexError).
                                                    $endgroup$
                                                    – Chas Brown
                                                    1 hour ago













                                                    $begingroup$
                                                    ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    1 hour ago





                                                    $begingroup$
                                                    ...or p[:1]in(s[:1],'+')and... fixes the edge cases @ChasBrown and I pointed out for a cost of 2 bytes.
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    1 hour ago













                                                    $begingroup$
                                                    Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    45 mins ago




                                                    $begingroup$
                                                    Fails another edge case of a trailing '+' (e.g. f('a/b', 'a/+')) but fixable in 0 bytes with ...or(s[:1]in'/')*2:]).
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    45 mins ago












                                                    $begingroup$
                                                    Try it online is always recommended!
                                                    $endgroup$
                                                    – Chas Brown
                                                    44 mins ago




                                                    $begingroup$
                                                    Try it online is always recommended!
                                                    $endgroup$
                                                    – Chas Brown
                                                    44 mins ago











                                                    0












                                                    $begingroup$


                                                    Clojure, 107 91 76 65 72 102 bytes



                                                    An anonymous function, returns subject topic as truthy and nil as falsey (valid in Clojure).



                                                    (defn ?[t c](every? #(#"#""+"(% 0)(% 1))(apply #(map vector % %2)(map #(re-seq #"[^/]+" %) [t c]))))


                                                    107 102 working
                                                    91 76 65 all defeated with regex chars






                                                    share|improve this answer











                                                    $endgroup$












                                                    • $begingroup$
                                                      ...and my comment under your question becomes pertinent
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      7 hours ago











                                                    • $begingroup$
                                                      @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                      $endgroup$
                                                      – Patrick
                                                      2 hours ago










                                                    • $begingroup$
                                                      I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago










                                                    • $begingroup$
                                                      @ChasBrown, correct, and with ^ instead of $; thanks.
                                                      $endgroup$
                                                      – Patrick
                                                      1 hour ago






                                                    • 1




                                                      $begingroup$
                                                      Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago















                                                    0












                                                    $begingroup$


                                                    Clojure, 107 91 76 65 72 102 bytes



                                                    An anonymous function, returns subject topic as truthy and nil as falsey (valid in Clojure).



                                                    (defn ?[t c](every? #(#"#""+"(% 0)(% 1))(apply #(map vector % %2)(map #(re-seq #"[^/]+" %) [t c]))))


                                                    107 102 working
                                                    91 76 65 all defeated with regex chars






                                                    share|improve this answer











                                                    $endgroup$












                                                    • $begingroup$
                                                      ...and my comment under your question becomes pertinent
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      7 hours ago











                                                    • $begingroup$
                                                      @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                      $endgroup$
                                                      – Patrick
                                                      2 hours ago










                                                    • $begingroup$
                                                      I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago










                                                    • $begingroup$
                                                      @ChasBrown, correct, and with ^ instead of $; thanks.
                                                      $endgroup$
                                                      – Patrick
                                                      1 hour ago






                                                    • 1




                                                      $begingroup$
                                                      Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago













                                                    0












                                                    0








                                                    0





                                                    $begingroup$


                                                    Clojure, 107 91 76 65 72 102 bytes



                                                    An anonymous function, returns subject topic as truthy and nil as falsey (valid in Clojure).



                                                    (defn ?[t c](every? #(#"#""+"(% 0)(% 1))(apply #(map vector % %2)(map #(re-seq #"[^/]+" %) [t c]))))


                                                    107 102 working
                                                    91 76 65 all defeated with regex chars






                                                    share|improve this answer











                                                    $endgroup$




                                                    Clojure, 107 91 76 65 72 102 bytes



                                                    An anonymous function, returns subject topic as truthy and nil as falsey (valid in Clojure).



                                                    (defn ?[t c](every? #(#"#""+"(% 0)(% 1))(apply #(map vector % %2)(map #(re-seq #"[^/]+" %) [t c]))))


                                                    107 102 working
                                                    91 76 65 all defeated with regex chars







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited 52 mins ago

























                                                    answered 7 hours ago









                                                    PatrickPatrick

                                                    1814 bronze badges




                                                    1814 bronze badges











                                                    • $begingroup$
                                                      ...and my comment under your question becomes pertinent
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      7 hours ago











                                                    • $begingroup$
                                                      @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                      $endgroup$
                                                      – Patrick
                                                      2 hours ago










                                                    • $begingroup$
                                                      I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago










                                                    • $begingroup$
                                                      @ChasBrown, correct, and with ^ instead of $; thanks.
                                                      $endgroup$
                                                      – Patrick
                                                      1 hour ago






                                                    • 1




                                                      $begingroup$
                                                      Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago
















                                                    • $begingroup$
                                                      ...and my comment under your question becomes pertinent
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      7 hours ago











                                                    • $begingroup$
                                                      @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                      $endgroup$
                                                      – Patrick
                                                      2 hours ago










                                                    • $begingroup$
                                                      I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                      $endgroup$
                                                      – Chas Brown
                                                      1 hour ago










                                                    • $begingroup$
                                                      @ChasBrown, correct, and with ^ instead of $; thanks.
                                                      $endgroup$
                                                      – Patrick
                                                      1 hour ago






                                                    • 1




                                                      $begingroup$
                                                      Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                      $endgroup$
                                                      – Jonathan Allan
                                                      1 hour ago















                                                    $begingroup$
                                                    ...and my comment under your question becomes pertinent
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    7 hours ago





                                                    $begingroup$
                                                    ...and my comment under your question becomes pertinent
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    7 hours ago













                                                    $begingroup$
                                                    @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                    $endgroup$
                                                    – Patrick
                                                    2 hours ago




                                                    $begingroup$
                                                    @JonathanAllan, indeed, except + and # do not appear in subject topic strings :)
                                                    $endgroup$
                                                    – Patrick
                                                    2 hours ago












                                                    $begingroup$
                                                    I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                    $endgroup$
                                                    – Chas Brown
                                                    1 hour ago




                                                    $begingroup$
                                                    I think this fails for subject music/kei$ha/latest and criteria +/kei$ha/+ (which should match and is valid ASCII).
                                                    $endgroup$
                                                    – Chas Brown
                                                    1 hour ago












                                                    $begingroup$
                                                    @ChasBrown, correct, and with ^ instead of $; thanks.
                                                    $endgroup$
                                                    – Patrick
                                                    1 hour ago




                                                    $begingroup$
                                                    @ChasBrown, correct, and with ^ instead of $; thanks.
                                                    $endgroup$
                                                    – Patrick
                                                    1 hour ago




                                                    1




                                                    1




                                                    $begingroup$
                                                    Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    1 hour ago




                                                    $begingroup$
                                                    Try with 'Q' before and 'E' after the pattern prior to the replace - source
                                                    $endgroup$
                                                    – Jonathan Allan
                                                    1 hour ago

















                                                    draft saved

                                                    draft discarded
















































                                                    If this is an answer to a challenge…



                                                    • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                    • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                      Explanations of your answer make it more interesting to read and are very much encouraged.


                                                    • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                                    More generally…



                                                    • …Please make sure to answer the question and provide sufficient detail.


                                                    • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f188397%2fmqtt-subscription-topic-match%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                                    199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單