How can I split a string using regex to return a list of values?

前端 未结 8 1347
感动是毒
感动是毒 2021-01-25 11:42

How can I take the string foo[]=1&foo[]=5&foo[]=2 and return a collection with the values 1,5,2 in that order. I am looking for an answer using

相关标签:
8条回答
  • 2021-01-25 12:07

    This should do:

    using System.Text.RegularExpressions;
    
    Regex.Replace(s, !@"^[0-9]*$”, "");
    

    Where s is your String where you want the numbers to be extracted.

    0 讨论(0)
  • 2021-01-25 12:09

    I don't know C#, but...

    In java:

    String[] nums = String.split(yourString, "&?foo[]");
    

    The second argument in the String.split() method is a regex telling the method where to split the String.

    0 讨论(0)
提交回复
热议问题