Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Isn't ?= needless?

Isn't ?= needless?

Scheduled Pinned Locked Moved Regular Expressions
questionlinuxalgorithmsregextutorial
4 Posts 2 Posters 13 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 15708820
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • M Member 15708820

      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.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • D 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 Kreskowiak

        M Offline
        M Offline
        Member 15708820
        wrote on last edited by
        #3

        Thank you for the link. In the meantime I think, I have found out, what the difference is between abc(?=.*xyz) and abc.*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 both abc(?=.*xyz) and abc.*xyz. But 4. is different.

        D 1 Reply Last reply
        0
        • M Member 15708820

          Thank you for the link. In the meantime I think, I have found out, what the difference is between abc(?=.*xyz) and abc.*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 both abc(?=.*xyz) and abc.*xyz. But 4. is different.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups