How to match with "\*" but not with "/\*" in regex?

by mallory_cormier , in category: Third Party Scripts , a day ago

How to match with "\*" but not with "/\*" in regex?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by jasen , 34 minutes ago

@mallory_cormier 

To match with "*" but not with "/*", you can use a negative lookbehind assertion in your regex pattern. Here is an example of a regex pattern that matches with "*" but not with "/*":

1
(?<!/)*


Explanation:

  • (?: Negative lookbehind assertion that checks if the preceding character is not "/"
  • *: Matches with the literal character "*"


This regex pattern will match with any occurrence of "*" that is not preceded by a "/".