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. Positive Lookbehind question

Positive Lookbehind question

Scheduled Pinned Locked Moved Regular Expressions
question
3 Posts 2 Posters 20 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.
  • T Offline
    T Offline
    tasoss
    wrote on last edited by
    #1

    Hello. I'm trying to understand why '(?<=a)[1-9]+' works with "a556" but 'F(?<=a)[1-9]+' doesn't work with "Fa556". Thanks!

    T 1 Reply Last reply
    0
    • T tasoss

      Hello. I'm trying to understand why '(?<=a)[1-9]+' works with "a556" but 'F(?<=a)[1-9]+' doesn't work with "Fa556". Thanks!

      T Offline
      T Offline
      Terry R 2023
      wrote on last edited by
      #2

      I would suggest reading up on lookbehinds @ Advanced Regex Tutorial—Regex Syntax[^] . You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match. The second regex, due to the "F" being first in the expression means it finds a "F", then attempts to look for an "a" before the "F" which does not fit your example text. So this is a lookbehind after the match, your first regex was a lookbehind before the match. You should put the "F" together with the "a" inside the lookbehind. Maybe you didn't for some reason known only to you. Since you have provided very little context for the 2 expressions and examples I can't help any further currently. Terry

      T 1 Reply Last reply
      0
      • T Terry R 2023

        I would suggest reading up on lookbehinds @ Advanced Regex Tutorial—Regex Syntax[^] . You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match. The second regex, due to the "F" being first in the expression means it finds a "F", then attempts to look for an "a" before the "F" which does not fit your example text. So this is a lookbehind after the match, your first regex was a lookbehind before the match. You should put the "F" together with the "a" inside the lookbehind. Maybe you didn't for some reason known only to you. Since you have provided very little context for the 2 expressions and examples I can't help any further currently. Terry

        T Offline
        T Offline
        tasoss
        wrote on last edited by
        #3

        Hello and thank you very much for your reply. Firstly i have to read the article you have mentioned and then we can talk again. But i believe this

        You see the expression (?<=) can be used both as lookbehind before the match and lookbehind after the match.

        is the most important thing that i didn't know. Can you choose if (?<=) will be treated as before or after only ??? (i will found out after reading the article :)

        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