Sublime Forum

RegEx working in tester but not in .sublime-syntax

#1

Hello,

I’m new to both RegEx and YAML.
I’m trying to create a custom syntax highlight.

I used the following RegEx:
((^[0-9a-zA-Z_\-]{6} {1})|(^ {7}))([0-9A-Z_\-\S]*\.$)
to try and highlight a line that begin with either

  • XXXXXX_[NAME ending with a dot]
  • ________[NAME ending with a dot]
    where _ is a whitespace.

The RegEx works on site like https://regex101.com/ but not in Sublime Text

0 Likes

#2

Works fine.

%YAML 1.2
---
# https://www.sublimetext.com/docs/syntax.html
name: Custom Syntax
scope: source.custom
version: 2

contexts:
  main:
    - match: ((^[0-9a-zA-Z_\-]{6} {1})|(^ {7}))([0-9A-Z_\-\S]*\.$)
      scope: constant.other

grafik

0 Likes

#3

Sorry for the late reply.
It doesn’t work at all on my version (Build 4169).
Could the problem be that I’m using the portable version?

- match: ((^[0-9a-zA-Z_\-]{6} {1})|(^ {7}))([0-9A-Z_\-\S]*\.$)
  scope: entity.name.section.cobol

image

0 Likes

#4

I am using exactly the same build.

Maybe other rules in your syntax are involved?

0 Likes

#5

That was the issue, the seven spaces where in another scope.

Thanks a lot!

0 Likes