none
Regex for comma separated strings RRS feed

  • Question

  • Hi all, I am trying to write a regex for a comma delimited strings, It should be accepting any string of format Name,Name and name should be alpha. One more thing is this validation should happen only if one particular listitem of a radiobuttonlist is selected and should not do validation for other listitems, my concern is i should do it without javascript.Help me with this guys.

    Thanks in advance.

    • Moved by Lisa Zhu Friday, June 7, 2013 2:31 AM Regular Expressions Related problem
    Thursday, June 6, 2013 4:26 AM

Answers

  • Hi Ricky.net ,

    please try

    \b[A-Z0-9._%+-]+,[A-Z0-9.-]\S+

    i think it will return what you need (name,name)


    Mark Answered and Vote if you found this helpful :) Ahmed Ismail


    Thursday, June 6, 2013 6:55 AM
  • Hi.

    If this is a school assignment, you're best off actually learning .NET Regular Expressions instead of asking someone to create a pattern for you. I know Regular expressions look like malborge, but that's not something you should be intimidated by. Take my word for it, they are surprisingly easy to learn. Dedicate one day for studying them, and you will find that no string parsing task is a problem for you ever again!

    Regular expressions are kind of like one way hashes. They are easy to create, and they work. But they are almost impossible to read once created, except by the author perhaps.

    If it's not a school assignment, and you just need the functionality, use String.Split instead, RegEx is definitely an overkill for splitting a string by a delimiter. Though you should still learn it.


    Teo Selenius

    Friday, June 7, 2013 8:24 AM

All replies

  • Hi Ricky.net ,

    please try

    \b[A-Z0-9._%+-]+,[A-Z0-9.-]\S+

    i think it will return what you need (name,name)


    Mark Answered and Vote if you found this helpful :) Ahmed Ismail


    Thursday, June 6, 2013 6:55 AM
  • Could you show us some realistic examples for this strings to match, please.

    Kind regards,

    wizend

    Thursday, June 6, 2013 7:58 AM
  • Hi Wizend,

    I could be like Ricky,Smith or John,Legend etc....


    Ricky

    Friday, June 7, 2013 2:10 AM
  • Hi Ricky,

    I will move this thread to the most related forum for better support.

    Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 7, 2013 2:30 AM
  • Hi.

    If this is a school assignment, you're best off actually learning .NET Regular Expressions instead of asking someone to create a pattern for you. I know Regular expressions look like malborge, but that's not something you should be intimidated by. Take my word for it, they are surprisingly easy to learn. Dedicate one day for studying them, and you will find that no string parsing task is a problem for you ever again!

    Regular expressions are kind of like one way hashes. They are easy to create, and they work. But they are almost impossible to read once created, except by the author perhaps.

    If it's not a school assignment, and you just need the functionality, use String.Split instead, RegEx is definitely an overkill for splitting a string by a delimiter. Though you should still learn it.


    Teo Selenius

    Friday, June 7, 2013 8:24 AM