Isn't ?= needless?
-
Hello, I am learning Regex. I use Regex for a file-searching programme in Linux. (FSearch) I do not understand, why we need
?=
in Regex. It looks for me like?=
is needless. Why do I think so? Here is an example:abc(?=.*xyz)
But isn't this exactly the same like:
abc.*xyz
So actually my question is: Can you give me an example, where
?=
is really needed, because I can not get the same result without?=
? Would appreciate some answers. Thank you. -
Hello, I am learning Regex. I use Regex for a file-searching programme in Linux. (FSearch) I do not understand, why we need
?=
in Regex. It looks for me like?=
is needless. Why do I think so? Here is an example:abc(?=.*xyz)
But isn't this exactly the same like:
abc.*xyz
So actually my question is: Can you give me an example, where
?=
is really needed, because I can not get the same result without?=
? Would appreciate some answers. Thank you.No, they are not the same. You proved it yourself with your own experiment. Is it useful? In your example, that depends on the context in which the expression is being used. There's a good read on the "look ahead asseertion" at Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions[^].
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak -
No, they are not the same. You proved it yourself with your own experiment. Is it useful? In your example, that depends on the context in which the expression is being used. There's a good read on the "look ahead asseertion" at Regex Tutorial - Lookahead and Lookbehind Zero-Length Assertions[^].
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave KreskowiakThank you for the link. In the meantime I think, I have found out, what the difference is between
abc(?=.*xyz)
andabc.*xyz
We have 4 elements: 1. The regex search command string 2. The strings (e.g. the names of the files). 3. The strings that had a result (e.g. the file names that have a result). 4. The result for each string (The match within each string) 2-3 are the same for bothabc(?=.*xyz)
andabc.*xyz
. But 4. is different. -
Thank you for the link. In the meantime I think, I have found out, what the difference is between
abc(?=.*xyz)
andabc.*xyz
We have 4 elements: 1. The regex search command string 2. The strings (e.g. the names of the files). 3. The strings that had a result (e.g. the file names that have a result). 4. The result for each string (The match within each string) 2-3 are the same for bothabc(?=.*xyz)
andabc.*xyz
. But 4. is different.If you want to experiment with your expression, Google for "Expresso 3". It's free and an indispensable tool for understanding regular expressions.
Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
Dave Kreskowiak