0

I'm trying to match a TeX command, i.e. a backslash followed by a word (in a desired list) using regex, but with any number of them. For example, if the list I want is test, other, list, then the sequences \test, \other, and \list should be matched, while \sdfsdf should not. I also would want \test\list and \test\other\list to be matched. However, I don't want to match things like \testagain (although \test again should be). I tried the following regex

(\\)(test|other|list)([^a-z])

to no avail, since it does not match \test\other. How would I do this? I am not very experienced with regex.

Ken White
  • 123,280
  • 14
  • 225
  • 444
btshepard
  • 131
  • 5

1 Answers1

1

Use \b to match the word boundary at the end of the word.

\\(test|other|list)\b
Barmar
  • 741,623
  • 53
  • 500
  • 612