Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, you can use regex to match a certain number of characters before a specific string by using the positive lookbehind assertion. For example, if you want to match 3 characters before the string "hello", you could use the following regex:

(?<=.{3})hello

To use curly braces in reverse, you could use the negative lookbehind assertion. For example, if you want to match "world" only if it is not preceded by 2 or more digits, you could use the following regex:

(?<!\d{2,})world

This will match "world" only if it is not immediately preceded by two or more digits.