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. RegEx question How to string match to New String?

RegEx question How to string match to New String?

Scheduled Pinned Locked Moved C#
questionregexhelptutorial
2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi everyone, I have a string like: "[FormField width=30 type=upload]" Using RegEx, I want to take the value of "type", and of width, and output them to their own seperate strings. How do I do this? I thought I might be able to do this using Regex.Match, but that just modifies the original string, not write them out to new strings. Any help with this is greatly appreciated. Thank you!

    E 1 Reply Last reply
    0
    • L Lost User

      Hi everyone, I have a string like: "[FormField width=30 type=upload]" Using RegEx, I want to take the value of "type", and of width, and output them to their own seperate strings. How do I do this? I thought I might be able to do this using Regex.Match, but that just modifies the original string, not write them out to new strings. Any help with this is greatly appreciated. Thank you!

      E Offline
      E Offline
      Eric Gunnerson msft
      wrote on last edited by
      #2

      Use a regex like: @"width=(\d+) type=(.+)]"; if this matches, look in the match.Groups[0] for the first value, and [1] for the second value. You can also use named captures: @"width=(?\d+) type=(?.+)]"; and then use match.Groups["width"] and ["type"]. That really helps the readability of code.

      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