How to crop strings using regular expressions? [closed]












-6















Here's the phrase I'd like to convert.



Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC


I wanna pick up these words Summoner1, Summoner2, Summoner3, Summoner4.
I suppose I should detect the strings "joined the lobby", and ": " using regular expression(regex) but I have no clue how to.



Thank you in advance.



Codes for extra question.
var list = @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";
var result = string.Join("|", list.Select(x => Regex.Replace(x, "( |:).*", string.Empty)));










share|improve this question















closed as too broad by Daniel A. White, Alexei Levenkov, Daniel Mann, ggorlen, gnat Jan 19 at 7:49


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • input.Split(new {':',' '}).First()

    – TheGeneral
    Jan 19 at 3:51
















-6















Here's the phrase I'd like to convert.



Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC


I wanna pick up these words Summoner1, Summoner2, Summoner3, Summoner4.
I suppose I should detect the strings "joined the lobby", and ": " using regular expression(regex) but I have no clue how to.



Thank you in advance.



Codes for extra question.
var list = @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";
var result = string.Join("|", list.Select(x => Regex.Replace(x, "( |:).*", string.Empty)));










share|improve this question















closed as too broad by Daniel A. White, Alexei Levenkov, Daniel Mann, ggorlen, gnat Jan 19 at 7:49


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • input.Split(new {':',' '}).First()

    – TheGeneral
    Jan 19 at 3:51














-6












-6








-6








Here's the phrase I'd like to convert.



Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC


I wanna pick up these words Summoner1, Summoner2, Summoner3, Summoner4.
I suppose I should detect the strings "joined the lobby", and ": " using regular expression(regex) but I have no clue how to.



Thank you in advance.



Codes for extra question.
var list = @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";
var result = string.Join("|", list.Select(x => Regex.Replace(x, "( |:).*", string.Empty)));










share|improve this question
















Here's the phrase I'd like to convert.



Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC


I wanna pick up these words Summoner1, Summoner2, Summoner3, Summoner4.
I suppose I should detect the strings "joined the lobby", and ": " using regular expression(regex) but I have no clue how to.



Thank you in advance.



Codes for extra question.
var list = @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";
var result = string.Join("|", list.Select(x => Regex.Replace(x, "( |:).*", string.Empty)));







c# regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 6:41







XHSKR

















asked Jan 19 at 3:34









XHSKRXHSKR

12




12




closed as too broad by Daniel A. White, Alexei Levenkov, Daniel Mann, ggorlen, gnat Jan 19 at 7:49


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by Daniel A. White, Alexei Levenkov, Daniel Mann, ggorlen, gnat Jan 19 at 7:49


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • input.Split(new {':',' '}).First()

    – TheGeneral
    Jan 19 at 3:51



















  • input.Split(new {':',' '}).First()

    – TheGeneral
    Jan 19 at 3:51

















input.Split(new {':',' '}).First()

– TheGeneral
Jan 19 at 3:51





input.Split(new {':',' '}).First()

– TheGeneral
Jan 19 at 3:51












2 Answers
2






active

oldest

votes


















0














If you want to use Regex, you can use the following.



"( |:).*"


Example,



var list= @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";


var result = list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));


Update: Based on Comment



var result = string.Join("|",list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));


Output



Summoner1|Summoner2|Summoner3|Summoner4





share|improve this answer


























  • thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

    – XHSKR
    Jan 19 at 5:51











  • you mean the input string would be in mentioned format or result ?

    – Anu Viswan
    Jan 19 at 5:53











  • yeah the latter one. the result.

    – XHSKR
    Jan 19 at 5:57













  • @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

    – Anu Viswan
    Jan 19 at 6:00











  • I have updated the question. it says unable to convert from char to string.

    – XHSKR
    Jan 19 at 6:13



















0














       string sourc = @"Summoner1 joined the lobby.
Summoner2 jonied the lobby.
Summoner3: Top
Summoner4: ADC";
Regex reg = new Regex("^[\s]*(Summoner[\d])+.*$", RegexOptions.Multiline);
var result = reg.Matches(sourc).ToList().Select(x => x.Groups[1].Value).ToList();





share|improve this answer






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you want to use Regex, you can use the following.



    "( |:).*"


    Example,



    var list= @"Summoner1 joined the lobby.
    Summoner2 jonied the lobby.
    Summoner3: Top
    Summoner4: ADC";


    var result = list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));


    Update: Based on Comment



    var result = string.Join("|",list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));


    Output



    Summoner1|Summoner2|Summoner3|Summoner4





    share|improve this answer


























    • thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

      – XHSKR
      Jan 19 at 5:51











    • you mean the input string would be in mentioned format or result ?

      – Anu Viswan
      Jan 19 at 5:53











    • yeah the latter one. the result.

      – XHSKR
      Jan 19 at 5:57













    • @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

      – Anu Viswan
      Jan 19 at 6:00











    • I have updated the question. it says unable to convert from char to string.

      – XHSKR
      Jan 19 at 6:13
















    0














    If you want to use Regex, you can use the following.



    "( |:).*"


    Example,



    var list= @"Summoner1 joined the lobby.
    Summoner2 jonied the lobby.
    Summoner3: Top
    Summoner4: ADC";


    var result = list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));


    Update: Based on Comment



    var result = string.Join("|",list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));


    Output



    Summoner1|Summoner2|Summoner3|Summoner4





    share|improve this answer


























    • thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

      – XHSKR
      Jan 19 at 5:51











    • you mean the input string would be in mentioned format or result ?

      – Anu Viswan
      Jan 19 at 5:53











    • yeah the latter one. the result.

      – XHSKR
      Jan 19 at 5:57













    • @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

      – Anu Viswan
      Jan 19 at 6:00











    • I have updated the question. it says unable to convert from char to string.

      – XHSKR
      Jan 19 at 6:13














    0












    0








    0







    If you want to use Regex, you can use the following.



    "( |:).*"


    Example,



    var list= @"Summoner1 joined the lobby.
    Summoner2 jonied the lobby.
    Summoner3: Top
    Summoner4: ADC";


    var result = list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));


    Update: Based on Comment



    var result = string.Join("|",list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));


    Output



    Summoner1|Summoner2|Summoner3|Summoner4





    share|improve this answer















    If you want to use Regex, you can use the following.



    "( |:).*"


    Example,



    var list= @"Summoner1 joined the lobby.
    Summoner2 jonied the lobby.
    Summoner3: Top
    Summoner4: ADC";


    var result = list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty));


    Update: Based on Comment



    var result = string.Join("|",list.Split(new {Environment.NewLine},StringSplitOptions.RemoveEmptyEntries).Select(x=> Regex.Replace(x,"( |:).*",string.Empty)));


    Output



    Summoner1|Summoner2|Summoner3|Summoner4






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 19 at 6:23

























    answered Jan 19 at 5:01









    Anu ViswanAnu Viswan

    4,5232524




    4,5232524













    • thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

      – XHSKR
      Jan 19 at 5:51











    • you mean the input string would be in mentioned format or result ?

      – Anu Viswan
      Jan 19 at 5:53











    • yeah the latter one. the result.

      – XHSKR
      Jan 19 at 5:57













    • @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

      – Anu Viswan
      Jan 19 at 6:00











    • I have updated the question. it says unable to convert from char to string.

      – XHSKR
      Jan 19 at 6:13



















    • thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

      – XHSKR
      Jan 19 at 5:51











    • you mean the input string would be in mentioned format or result ?

      – Anu Viswan
      Jan 19 at 5:53











    • yeah the latter one. the result.

      – XHSKR
      Jan 19 at 5:57













    • @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

      – Anu Viswan
      Jan 19 at 6:00











    • I have updated the question. it says unable to convert from char to string.

      – XHSKR
      Jan 19 at 6:13

















    thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

    – XHSKR
    Jan 19 at 5:51





    thank you for your answer so very much. Would you be so kind as to answer the following question? I want it to be in the same line like Summoner1|Summoner2|Summoner3|Summoner4 to be able to use regex multiple matches.

    – XHSKR
    Jan 19 at 5:51













    you mean the input string would be in mentioned format or result ?

    – Anu Viswan
    Jan 19 at 5:53





    you mean the input string would be in mentioned format or result ?

    – Anu Viswan
    Jan 19 at 5:53













    yeah the latter one. the result.

    – XHSKR
    Jan 19 at 5:57







    yeah the latter one. the result.

    – XHSKR
    Jan 19 at 5:57















    @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

    – Anu Viswan
    Jan 19 at 6:00





    @XHSKR I have updated the answer for you, you can use string.Join for the purpose.

    – Anu Viswan
    Jan 19 at 6:00













    I have updated the question. it says unable to convert from char to string.

    – XHSKR
    Jan 19 at 6:13





    I have updated the question. it says unable to convert from char to string.

    – XHSKR
    Jan 19 at 6:13













    0














           string sourc = @"Summoner1 joined the lobby.
    Summoner2 jonied the lobby.
    Summoner3: Top
    Summoner4: ADC";
    Regex reg = new Regex("^[\s]*(Summoner[\d])+.*$", RegexOptions.Multiline);
    var result = reg.Matches(sourc).ToList().Select(x => x.Groups[1].Value).ToList();





    share|improve this answer




























      0














             string sourc = @"Summoner1 joined the lobby.
      Summoner2 jonied the lobby.
      Summoner3: Top
      Summoner4: ADC";
      Regex reg = new Regex("^[\s]*(Summoner[\d])+.*$", RegexOptions.Multiline);
      var result = reg.Matches(sourc).ToList().Select(x => x.Groups[1].Value).ToList();





      share|improve this answer


























        0












        0








        0







               string sourc = @"Summoner1 joined the lobby.
        Summoner2 jonied the lobby.
        Summoner3: Top
        Summoner4: ADC";
        Regex reg = new Regex("^[\s]*(Summoner[\d])+.*$", RegexOptions.Multiline);
        var result = reg.Matches(sourc).ToList().Select(x => x.Groups[1].Value).ToList();





        share|improve this answer













               string sourc = @"Summoner1 joined the lobby.
        Summoner2 jonied the lobby.
        Summoner3: Top
        Summoner4: ADC";
        Regex reg = new Regex("^[\s]*(Summoner[\d])+.*$", RegexOptions.Multiline);
        var result = reg.Matches(sourc).ToList().Select(x => x.Groups[1].Value).ToList();






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 6:17









        windfogwindfog

        1898




        1898















            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage