regex search
-
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 !
-
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 !
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.
-
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 !
I'd capture them in named groups:
name:\[(?'Name'[^\]]*)\],family:\[(?'Family'[^\]]*)\],Age:\[(?'Age'[^\]]*)\]
And we have a Regular Expression forum here. -
I'd capture them in named groups:
name:\[(?'Name'[^\]]*)\],family:\[(?'Family'[^\]]*)\],Age:\[(?'Age'[^\]]*)\]
And we have a Regular Expression forum here.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);
}