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. Problem capturing last group in a line: CLOSED

Problem capturing last group in a line: CLOSED

Scheduled Pinned Locked Moved Regular Expressions
helpregexquestion
3 Posts 2 Posters 2 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
    mo1492
    wrote on last edited by
    #1

    Don't know if this is the correct solution but it seems to work. Using the RegexOptions.RightToLeft option seems to work. I'm not too familiar with Regex. I've created an expression to capture data in a line and it works except for the last group DataType which does not extract the value "dtText". Can someone help? Thank You Expression: FieldName=(?.*?),ColumnWidth=(?.*?),Size=(?.*?),DataType=(?.*?) Data: FieldName=Field1,ColumnWidth=50,Size=10,DataType=dtText Output: FieldName: [Field1] ColumnWidth: [50] Size: [10] DataType []

    Richard DeemingR 1 Reply Last reply
    0
    • M mo1492

      Don't know if this is the correct solution but it seems to work. Using the RegexOptions.RightToLeft option seems to work. I'm not too familiar with Regex. I've created an expression to capture data in a line and it works except for the last group DataType which does not extract the value "dtText". Can someone help? Thank You Expression: FieldName=(?.*?),ColumnWidth=(?.*?),Size=(?.*?),DataType=(?.*?) Data: FieldName=Field1,ColumnWidth=50,Size=10,DataType=dtText Output: FieldName: [Field1] ColumnWidth: [50] Size: [10] DataType []

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      .*? tells the expression to capture as little as possible. Since there's nothing to match after the last expression, the least it can capture is nothing, so that's precisely what it does. If you're looking to capture everything up to the end of the line, then you'll want to add an end-of-line anchor:

      ...,DataType=(?<DataType>.*?)$


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        .*? tells the expression to capture as little as possible. Since there's nothing to match after the last expression, the least it can capture is nothing, so that's precisely what it does. If you're looking to capture everything up to the end of the line, then you'll want to add an end-of-line anchor:

        ...,DataType=(?<DataType>.*?)$


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        mo1492
        wrote on last edited by
        #3

        Thank you for your help :)

        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