HISE Logo Forum
    • Categories
    • Register
    • Login

    Regex String Not Working

    Scheduled Pinned Locked Moved Scripting
    4 Posts 3 Posters 190 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CasmatC
      Casmat
      last edited by Casmat

      Hey!

      Had a bit of a regex problem. I basically want to use Engine.getRegexMatches to return me a value. Basically, I want to find all values after the following substring: " - " (it has spaces and ignore quotes) . For example, if the given string was: Thanks - For Helping. The result should be For Helping. I tried the following code: ".*? - " (ignore quotes) in regexr, But the result in hise is the opposite from what I want, I don't know if there is a way to invert the value to show the other part after " - ". Then I tried this code: "(?<= - ).*$" (ignore quotes) and it worked flawlessly, but when put into hise as a string, an error in the console pops up called Interface:! regex_error(error_syntax) Anyone know what could be wrong here?

      Thanks!

      i make music

      ulrikU 1 Reply Last reply Reply Quote 0
      • ulrikU
        ulrik @Casmat
        last edited by

        @Casmat I'm not familiar with regex but if it's working for your purpose you could use substring

        const strings = ["Thanks - For Helping", "Vielen dank - My Dear"]
        
        for (s in strings)
        	Console.print(s.substring(s.indexOf("-")+1, s.length).trim());
        

        logging:

        Interface: For Helping
        Interface: My Dear
        

        Hise Develop branch
        MacOs 15.3.1, Xcode 16.2
        http://musikboden.se

        Christoph HartC 1 Reply Last reply Reply Quote 0
        • Christoph HartC
          Christoph Hart @ulrik
          last edited by

          s.split("-")[1].trim() should do the trick too. Regex is overkill for this simple task, but the correct syntax for this would be

          const strings = ["Thanks - For Helping", "Vielen dank - My Dear"]
          
          for(s in strings)
          	Console.print(Engine.getRegexMatches(s, ".* - (.*)")[1].trim());
          
          1 Reply Last reply Reply Quote 0
          • CasmatC
            Casmat
            last edited by

            @ulrik @Christoph-Hart Thanks! Both work amazing! The trim() function was exactly what I was looking for! I had thought it cut out all whitespace characters, not just the start and end! Thanks for helping!

            i make music

            1 Reply Last reply Reply Quote 0
            • First post
              Last post

            49

            Online

            1.7k

            Users

            11.7k

            Topics

            102.1k

            Posts