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. Regular Expressions

Regular Expressions

Scheduled Pinned Locked Moved C#
help
2 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.
  • A Offline
    A Offline
    Abraham Durairaj
    wrote on last edited by
    #1

    Hello, can anyone help me in solving this issue. I have a string like "76/78NagdeviSt2ndFlrNagdeviM3" using regular expressions I would like to change it to "76/78 Nagdevi St 2nd Flr Nagdevi M3" Thanks in advance. Regards, Abraham

    A 1 Reply Last reply
    0
    • A Abraham Durairaj

      Hello, can anyone help me in solving this issue. I have a string like "76/78NagdeviSt2ndFlrNagdeviM3" using regular expressions I would like to change it to "76/78 Nagdevi St 2nd Flr Nagdevi M3" Thanks in advance. Regards, Abraham

      A Offline
      A Offline
      Al Gardner
      wrote on last edited by
      #2

      First can I suggest you get hold of Expresso or one of the other tools that lets you play with Regexes so you get the correct one. I believe you are trying to insert a space in front of every upperCase character, so the simplest Regex is ([A-Z]). Unfortunately however you cannot just Replace these as then you would end up with 76/78 agdevi t2nd lr agdevi 3 Regex regex = new Regex("([A-Z])"); input = regex.Replace("76/78NagdeviSt2ndFlrNagdeviM3"," "); Instead use a MatchEvaluator. This example demonstrates named targets, which is not the simplest way to achieve what you require, but does scale better with more complex Regexes. private string UpperEvaluator(Match match) { return " "+match.Groups["upper"].Value; } public string AddSpaces(string input) { Regex regex = new Regex("(?'upper'([A-Z]))"); return regex.Replace(input, new MatchEvaluator(this.HtmlStripEvaluator)); }

      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