Sublime Forum

ST2 about regex

#1

i use sublime text 2 to edit vhdl code, i want to use regex to highlight words after “beq”, for example: beq testloop, then highlight testloop. but i donot know how do make it.

does any could help me? :smile:

0 Likes

#2

Would you like to search by using the regex search from console input?
The pattern is: (?<=beq )\w+

If you need this as command in a plugin, use it so:

[code]
import sublime
import sublime_plugin

class SelectAfterBeqCommand(sublime_plugin.TextCommand):
def run(self, edit):
regions = self.view.find_all("(?<=beq )\w+")
selections = self.view.sel()
selections.clear()
selections.add_all(regions)[/code]
Bind the command “select_after_beq” to an hotkey.

0 Likes

#3

thanks for the help!

[quote=“BugFix”]Would you like to search by using the regex search from console input?
The pattern is: (?<=beq )\w+

If you need this as command in a plugin, use it so:

[code]
import sublime
import sublime_plugin

class SelectAfterBeqCommand(sublime_plugin.TextCommand):
def run(self, edit):
regions = self.view.find_all("(?<=beq )\w+")
selections = self.view.sel()
selections.clear()
selections.add_all(regions)[/code]
Bind the command “select_after_beq” to an hotkey.[/quote]

0 Likes