user12368065
user12368065

Reputation:

Match any word that starts with a character, Regex

I am writing an extension for vscode and I am using regular expressions for the grammers. I am currently trying to find every word that beings with * but if there is a solution that expands to any character feel free to suggest it.

Any suggestions so far that I have seen have not worked. I think how TextMatte processes these expressions are a bit different so I think that is why.

Example of what I want.

This is a *star word. Here is another *word with a star.
*start *word

Upvotes: 0

Views: 1276

Answers (2)

George
George

Reputation: 158

From what I know of TextMate, escaping characters works as normal, so matching to:

\*\w+

should give you the words you're looking for, that begin with a *.

Upvotes: 1

Schalton
Schalton

Reputation: 3104

(?<!\b)\*[a-zA-Z0-9_]+ if you want *first_name to be a word

(?<!\b)\*[a-zA-Z0-9]+ if you don't

Could also throw in other symbols

the (?<!\b) is a negative look ahead to avoid stuff like not*me

[a-zA-Z0-9] is a common way to select all numbers and letters + tells it 1 or more

https://regex101.com/r/epX4R9/1


I'm not familiar with TextMatte so apologies if this is unhelpful


per comments, TextMatte accepts the regex from json so the slashes needed to be escaped: (?<!\\b)\\*[a-zA-Z0-9_]+

Upvotes: 2

Related Questions