7

Is there a way to make Sublime Text highlight (match) only part of a regex search pattern?

For example, I want to exclusively highlight Text when searching for Some(Text).

2 Answers 2

3

Difficulty in getting a regex application to work will probably have a regex solution. In this case, lookarounds.

Example using a lookbehind:

  • Sample:

    SomeText
    
  • Regex:

    (?<=Some)(Text)
    
  • Match:

    Text
    
2
  • In order to match (Text), you need to escape the parentheses so the regex should be (?<=Some)\(Text\) Commented Nov 4, 2015 at 15:29
  • 1
    @NonlinearFruit as I interpret OP's intention, that's the regex put in search box, thus this solution is probably correct, no reason to downvote it
    – SΛLVΘ
    Commented Nov 23, 2015 at 10:04
4

You can use:

(?<=preceeding_enclosing_text)your_searched_text(?=following_enclosing_text)

In your particular example:

(?<=Some\().+?(?=\))

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .