Ask Your Question
4

How can a regular expression be crafted to leave out a string that has a particular size?

asked 2022-08-05 11:00:00 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-04-20 08:00:00 +0000

pufferfish gravatar image

To exclude a string of a particular size from a regular expression, you can use negative lookahead. For example, if you want to match all strings that are between 3 and 5 characters long but not the ones with the exact size of 4 characters, you can use the following regular expression:

^(?!.{4}$).{3,5}$

This negative lookahead expression (?!.{4}$) will exclude any string that has exactly 4 characters, and the rest of the regular expression will match any string between 3 and 5 characters long.

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: 2022-08-05 11:00:00 +0000

Seen: 20 times

Last updated: Apr 20 '22