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 search

regex search

Scheduled Pinned Locked Moved C#
regexquestion
4 Posts 3 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.
  • J Offline
    J Offline
    jojoba20
    wrote on last edited by
    #1

    hi, i have bellow text : name:[jojoba],family:[naiem],Age:[23] now wanna to get each item seperatly : somthing like :

    Regex _regexN2 = new Regex(string.Format("([{0}]+\\d+$*[]])", _regStyle));
    Match mN2 = _regexN2.Match(_textToSearch);
    if (mN2.Success)
    {
    mN2.value;
    }

    How can i do that !

    OriginalGriffO P 2 Replies Last reply
    0
    • J jojoba20

      hi, i have bellow text : name:[jojoba],family:[naiem],Age:[23] now wanna to get each item seperatly : somthing like :

      Regex _regexN2 = new Regex(string.Format("([{0}]+\\d+$*[]])", _regStyle));
      Match mN2 = _regexN2.Match(_textToSearch);
      if (mN2.Success)
      {
      mN2.value;
      }

      How can i do that !

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The first thing to do is: if you want multiple values, then use Regex.Matches instead of Regex.Match, or design an expression that returns multiple results. Try this, for example:

      Regex reg = new Regex(@"(?<=\[)(\w+?)(?=\])");
      string input = @"name:[jojoba],family:[naiem],Age:[23]";
      foreach (Match m in reg.Matches(input))
      {
      Console.WriteLine(m.Value);
      }

      This message is manufactured from fully recyclable noughts and ones. To recycle this message, please separate into two tidy piles, and take them to your nearest local recycling centre. Please note that in some areas noughts are always replaced with zeros by law, and many facilities cannot recycle zeroes - in this case, please bury them in your back garden and water frequently.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • J jojoba20

        hi, i have bellow text : name:[jojoba],family:[naiem],Age:[23] now wanna to get each item seperatly : somthing like :

        Regex _regexN2 = new Regex(string.Format("([{0}]+\\d+$*[]])", _regStyle));
        Match mN2 = _regexN2.Match(_textToSearch);
        if (mN2.Success)
        {
        mN2.value;
        }

        How can i do that !

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

        I'd capture them in named groups: name:\[(?'Name'[^\]]*)\],family:\[(?'Family'[^\]]*)\],Age:\[(?'Age'[^\]]*)\] And we have a Regular Expression forum here.

        J 1 Reply Last reply
        0
        • P PIEBALDconsult

          I'd capture them in named groups: name:\[(?'Name'[^\]]*)\],family:\[(?'Family'[^\]]*)\],Age:\[(?'Age'[^\]]*)\] And we have a Regular Expression forum here.

          J Offline
          J Offline
          jojoba20
          wrote on last edited by
          #4

          thanks for solution!

          string RegexGhaleb = _spliteGhaleb[p].Replace("[]", "").Replace("(", "{").Replace(")", "}");
          Regex regex = new Regex(RegexGhaleb + @"\[([^\]]*)\]");
          Match _mc = regex.Match(_msgSMS);
          string _result = _mc.Groups[1].ToString();
          if (_result != string.Empty)//قالب صحیح
          {
          if (typeKar == string.Empty)
          typeKar = _drRes[0]["TableName"].ToString();
          DataRow[] _drParams = _dtAllParams.Select(string.Format(" FarsiName like '%{0}%'", _spliteGhaleb[p].Replace(":[]", "").TrimEnd(' ')));
          _ParamToSave.Add(_drParams[0]["Param"].ToString(), _result);
          }

          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