How to match everything except a particular pattern after/before a specific string constant

Arash
ATS(inline, const, unused) /* Variadic Macro */
OTS(inline, const, unused)

I'm trying to match inline, const, unused keywords only in ATS macro. i tried ATS([^,]*) but it only matches inline keyword.

Edit: I need to change the color of all ATS parameters. this only works on the first parameter.

(font-lock-add-keywords nil
  '(("ATS(\\([^,]*\\)" 1 font-lock-builtin-face)))
Lindydancer

You can use an anchored font-lock rule. It's like a search within a search. The code below searches for AST(. Once it's found, it find the end of the argument list and performs a search for all words within it.

(defun foo ()
  (interactive)
  (setq font-lock-multiline t)
  (font-lock-add-keywords
   nil
   '(("\\_<ATS("
      ("\\_<\\sw+\\_>"
       ;; Pre-match form -- limit the sub-search to the end of the argument list.
       (save-excursion
         (goto-char (match-end 0))
         (backward-char)
         (ignore-errors
           (forward-sexp))
         (point))
       ;; Post-match form
       (goto-char (match-end 0))
       (0 font-lock-builtin-face))))))

This will match all words inside the parentheses, even if they are spread out across multiple lines.

The pre-match form has two purposes: It can position the point to a suitable locations and it controls the extend of the sub-search (where nil means the end of the line). The post-match form can, for example, be used to return the point to a good position for other keyword rules.

This can, of course, be extended to only highlight a specific set of words, but I leave that as an exercise.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Regex - how to match everything except a particular pattern

Match everything except a specific string

Match everything except a pattern and replace matched with string

Pattern to match everything except a string of 5 digits

Match everything after particular pattern except whitespace till next letter

Google sheet : REGEXREPLACE match everything except a particular pattern

How to replace everything except a specific pattern with sed?

Is there a way to match everything except a constant string using Go.Regexp?

How to sed -e 's///' everything except a specific pattern?

Regex: match everything but specific pattern

Match everything except my pattern (RegEx)

Regex to match everything except trailing pattern

Regex Match everything except words of particular flag format

How to string split, match, and output a specific pattern?

How to match specific pattern with regex in a serialised string

match everything up to first '/' after a specific pattern

Match everything other than a specific pattern in a number

Regex, how to select everything except pattern?

How to extract particular text after specific pattern in string

python regex, How to match everything except headings?

Match everything except a complex regex pattern and replace it in Pandas

How to match string of a certain pattern but exclude one specific pattern?

VBA Regex - How to match anything except a specific string?

Proguard: How to keep everything except specific condition?

Regular Expression: Match everything except one specific character

Regex: Match everything in text paragraph except specific phrases

How to count particular pattern in a string?

Remove everything from a string except a date with a certain pattern

What is a regex that will match everything above a specific string?