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. Value between brackets with a sperator character [modified]

Value between brackets with a sperator character [modified]

Scheduled Pinned Locked Moved Regular Expressions
regexhelpquestion
3 Posts 2 Posters 9 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.
  • G Offline
    G Offline
    Groulien
    wrote on last edited by
    #1

    I'm looking for a regex which can match the a value between brackets and deal with a seperator character within. This is the format I'm after: [?#?] where ? can be one or more characters and # is '+', '-' or '=' It should match the following. [1+1] [A=T] [AB=#1#2#3] So far I've got this: \[.*[\+-=]?\] But it doesn't work well, it includes text between the 'tags'. [A=B]ShouldNotInclude[1=3] (but it does ) I'm obviously doing something wrong,the whole regex probably. Anyone got an idea? Found the problem, not the solution. Problem is that it jumps to the last ']' character it can detect.

    modified on Thursday, May 26, 2011 9:15 AM

    G P 2 Replies Last reply
    0
    • G Groulien

      I'm looking for a regex which can match the a value between brackets and deal with a seperator character within. This is the format I'm after: [?#?] where ? can be one or more characters and # is '+', '-' or '=' It should match the following. [1+1] [A=T] [AB=#1#2#3] So far I've got this: \[.*[\+-=]?\] But it doesn't work well, it includes text between the 'tags'. [A=B]ShouldNotInclude[1=3] (but it does ) I'm obviously doing something wrong,the whole regex probably. Anyone got an idea? Found the problem, not the solution. Problem is that it jumps to the last ']' character it can detect.

      modified on Thursday, May 26, 2011 9:15 AM

      G Offline
      G Offline
      Groulien
      wrote on last edited by
      #2

      Got it: \[(.*?)[\+-=](.*?)\]

      1 Reply Last reply
      0
      • G Groulien

        I'm looking for a regex which can match the a value between brackets and deal with a seperator character within. This is the format I'm after: [?#?] where ? can be one or more characters and # is '+', '-' or '=' It should match the following. [1+1] [A=T] [AB=#1#2#3] So far I've got this: \[.*[\+-=]?\] But it doesn't work well, it includes text between the 'tags'. [A=B]ShouldNotInclude[1=3] (but it does ) I'm obviously doing something wrong,the whole regex probably. Anyone got an idea? Found the problem, not the solution. Problem is that it jumps to the last ']' character it can detect.

        modified on Thursday, May 26, 2011 9:15 AM

        P Offline
        P Offline
        Peter_in_2780
        wrote on last edited by
        #3

        What you saw is called 'greedy' matching. The better regex engines support non-greedy matching operators, which behave a bit more intuitively, even if they make the regex unreadable! Cheers, Peter

        Software rusts. Simon Stephenson, ca 1994.

        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