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. C#
  4. Help needed on RegEx.Split() / pattern for dealing with an escaping char. as separator [modified]

Help needed on RegEx.Split() / pattern for dealing with an escaping char. as separator [modified]

Scheduled Pinned Locked Moved C#
regexhelpquestion
5 Posts 2 Posters 0 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
    girm
    wrote on last edited by
    #1

    Hi there, I would much appreciate if anyone could help me on this problem that is sligthly driving me crazy, I've a string ... say "abc§123§§456§§§xyz" I'd like to split it in a string[] , using '§' as separator , now the trick is that '§' is (in this case) also an 'escape' char. (i.e. in the original string "§§" represent the '§' ... and therefore is not to be considered to be a separator for splitting). So I am expecting a split like : abc 123§456§ xyz My code is (so far): Regex regExSplit = new Regex("(? That split as abc 123§§456§§§xyz Thanks for any help :rolleyes: Marc -- modified at 4:51 Monday 16th April, 2007

    J 1 Reply Last reply
    0
    • G girm

      Hi there, I would much appreciate if anyone could help me on this problem that is sligthly driving me crazy, I've a string ... say "abc§123§§456§§§xyz" I'd like to split it in a string[] , using '§' as separator , now the trick is that '§' is (in this case) also an 'escape' char. (i.e. in the original string "§§" represent the '§' ... and therefore is not to be considered to be a separator for splitting). So I am expecting a split like : abc 123§456§ xyz My code is (so far): Regex regExSplit = new Regex("(? That split as abc 123§§456§§§xyz Thanks for any help :rolleyes: Marc -- modified at 4:51 Monday 16th April, 2007

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Escape char as seperator ...maybe I'm misunderstanding the question, but wouldn't you simply type a double §§ in the regex string?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: How men in the Catholic Church replaced Passover with Easter The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      G 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Escape char as seperator ...maybe I'm misunderstanding the question, but wouldn't you simply type a double §§ in the regex string?

        Tech, life, family, faith: Give me a visit. I'm currently blogging about: How men in the Catholic Church replaced Passover with Easter The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

        G Offline
        G Offline
        girm
        wrote on last edited by
        #3

        Sorry if I was not clear enough, if I use "§§" as a pattern the split of "abc§123§§456§§§xyz" will give abc§123 456 §xyz and this is not my expected abc 123§456§ xyz To try to make it clearer let's say that in the original string a substring like "§§" is to be understood as : since a "§" is followed by another "§" , then in the result string this second "§" is to be kept as is and not considered to be a separator (think of "\" instead of "§" if you prefer : "\\" means a real '\' not to be considered as a 'special' char. ... but that makes things quite unreadable in regex patterns) Thanks Marc hooktrack.girollet.com

        J 1 Reply Last reply
        0
        • G girm

          Sorry if I was not clear enough, if I use "§§" as a pattern the split of "abc§123§§456§§§xyz" will give abc§123 456 §xyz and this is not my expected abc 123§456§ xyz To try to make it clearer let's say that in the original string a substring like "§§" is to be understood as : since a "§" is followed by another "§" , then in the result string this second "§" is to be kept as is and not considered to be a separator (think of "\" instead of "§" if you prefer : "\\" means a real '\' not to be considered as a 'special' char. ... but that makes things quite unreadable in regex patterns) Thanks Marc hooktrack.girollet.com

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          I tried a couple of different regexes but wasn't able to accomplish this. Perhaps this is better asked in a regex forum?

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: How men in the Catholic Church replaced Passover with Easter The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          G 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            I tried a couple of different regexes but wasn't able to accomplish this. Perhaps this is better asked in a regex forum?

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: How men in the Catholic Church replaced Passover with Easter The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            G Offline
            G Offline
            girm
            wrote on last edited by
            #5

            :rose: Thanks much to have drop an eye, and spent of your time on this topic I'll take your advice and try the regex forum Take Care Marc

            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