Ask Your Question
3

Can you use Regex to match a certain number of characters before a specific string and use curly braces in reverse?

asked 2023-05-11 14:43:18 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-05-11 15:12:02 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-11 14:43:18 +0000

Seen: 11 times

Last updated: May 11 '23