Skip to content

Regular expression with ^ not recognized #160

Closed

Description

@alberti42

Thank you for the amazing ST4 package. It is super useful. I encountered issues with the default definition for Objective-C files:

{
            "syntax": "Objective-C/Objective-C",
            "match": "all",
            "rules": [
                {"globmatch": "**/*.m"},
                {"contains": "^\\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\\b|#import\\s+.+\\.h[\">])"}
            ]
        },

where I had to change the rule contains to:

{"contains": "\\s*(@(interface|class|protocol|property|end|synchronised|selector|implementation)\\b|#import\\s+.+\\.h[\">])"}

There, I removed ^ and it then worked. Do you know a simple explanation why ^ is not accepted? I checked with my .m files and the rule including ^ results in positive matches when using regex search functionality of ST4 editor. So, the problem should not be with my .m files.

Activity

  1. facelessuser commented on Feb 16, 2025

    @facelessuser
    Owner

    You'll have to provide me with a minimal example of what you are trying to match before I can look into this further. The pattern is great, but there is not enough context.

    Off the top of my head, it might be that you need to enable the multiline regex flag. I don't recall if that is enabled by default or not. It might not be.

  2. alberti42 commented on Feb 16, 2025

    @alberti42
    Author

    Thanks for the super quick reply. Just to avoid confusion or extra work for you, the JSON configuration I copied above was the default setting that you provided with your ST package. I copied it here for ease of reference.

    In my ST4, when I open any Objective C .m file (e.g., I am now working on this file, ST4 opens them with Wolfram syntax highlight, as it believes it is a file related to Wolfram Mathematica.

    Your ApplySyntax package works perfectly if I copy your default configuration and remove the caret char ^.

    I also have MATLAB syntax highlighting in my ST4 editor.

    Unfortunately, all three languages share the same extension .m That's why your package is so useful in these cases.

    Do you think it is sufficient for you to reproduce the issue?

  3. facelessuser commented on Feb 16, 2025

    @facelessuser
    Owner

    Please provide conflicting package links you use, such as the Wolfram Mathematica package.

    I'll try and reproduce when I get a chance.

  4. alberti42 commented on Feb 16, 2025

    @alberti42
    Author

    Thanks! I made it work with the default rule including ^. I don't know why the caret was so special. However, I found a mistake in the way my Objective-C.sublime-settings was configured:

    Instead of thiss:

    {
    	"translate_tabs_to_spaces": true,
    	"tab_size": 4,
    	"extensions":
    	[
    		"m",
    	],
    }

    I had for some strange reasons extensions set to an empty array. Now by, adding m, your ST package works like a charm.

    I am sorry if I bothered you with this issue. It was suspicious to me that it was only working without ^ in the regex. If you think everything is ok, let's close the issue.

  5. Repository owner locked and limited conversation to collaborators on Feb 18, 2025
  6. converted this issue into a discussion #161 on Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    S: triageIssue needs triage.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions