0

I am trying to match only the numbers after the following strings:

sequentialGrid: 650274
parallelGrid: 650274

My goal is to highlight the numbers, via M-x highlight-regexp after lines beginning with sequentialGrid: and parallelGrid:

Here was my attempt, using a Perl-like approach:

^sequentialGrid: \([0-9]*\).*/$1/

Unfortunately, Emacs does not support Perl functionality. Thus, I hope my request is not impossible or perhaps someone can offer a convenient workaround.

BTW I verified that ^sequentialGrid: \([0-9]*\).* highlights the entire line. I just need to extract the number.

modulitos
  • 14,737
  • 16
  • 67
  • 110
  • Never used emacs, but to do what you've described, use a positive lookbehind: e.g ``(?<=sequentialGrid:\s)[0-9]+`` will only match the number – badger5000 Jul 10 '14 at 08:52
  • No, it doesn't work. I think emacs' regexp lacks some of these features. I wonder if there is a workaround without sacrificing convenience? – modulitos Jul 10 '14 at 09:11
  • Oh....can you use a non-capturing group like ``(?:sequentialGrid:\s)[0-9]+`` ? – badger5000 Jul 10 '14 at 09:19
  • Sorry, put the number bit in brackets as well to capture that group: ``(?:sequentialGrid:\s)([0-9]+)`` – badger5000 Jul 10 '14 at 09:27
  • Still doesn't work. I found [this useful](http://stackoverflow.com/questions/1946352/comparison-table-for-emacs-regexp-and-perl-compatible-regular-expression-pcre) for using Perl with emacs, but emacs does not support PCRE as far as I know. I still hope to find an easy solution, if it exists. – modulitos Jul 10 '14 at 09:38

1 Answers1

2

If your goal is to add font-lock highlighting, the following expression will work:

(font-lock-add-keywords 
 nil
 '(("^\\(parallel\\|sequential\\)Grid:\\s-*\\([0-9]+\\)"
    2 font-lock-warning-face)))

The nil MODE parameter in it to the current buffer, or you could specify the mode name as a symbol. See the manual and the wiki for more on font-lock-add-keywords and font-lock-remove-keywords.

Dan
  • 5,209
  • 1
  • 25
  • 37