crackpanda Posted December 18, 2011 Share Posted December 18, 2011 As the subject implies, i need a regex for letters, one comma, and one space, does anyone know the solution? Thank you for your time, Quote Link to comment Share on other sites More sharing options...
silkfire Posted December 18, 2011 Share Posted December 18, 2011 ^A-Za-z ,$ Quote Link to comment Share on other sites More sharing options...
crackpanda Posted December 18, 2011 Author Share Posted December 18, 2011 I also now need one for: letters, spaces, and one comma I'm still trying to learn how to form these patterns.. Quote Link to comment Share on other sites More sharing options...
joe92 Posted December 19, 2011 Share Posted December 19, 2011 Could you give an example of input and desired output? What silkfire has given will match the literal string 'A-Za-z ,'. I'm guessing for your first question you were looking to match something more like 'said, '? In which case you will need to alter the pattern to look like: /[A-Za-z]+, / Placing the A-Z in the square brackets makes it a character class and will search for letters A to Z. Not inside the square brackets is just looking for the literal string 'A-Z', not the required result right? Also, you will not want the ^ sign at the beginning and the $ sign at the end. That will mean that the regex has to match from the beginning (^) till the end ($) of the input string. Again I'm presuming as you didn't provide an example with your question, but it sounds like you are looking for a match in a large section of text? Hope this helps, Joe Quote Link to comment Share on other sites More sharing options...
crackpanda Posted December 19, 2011 Author Share Posted December 19, 2011 Thanks for helping Joe, that code was close, it still lets in numbers in something like this "abc, 123, abc". I need letters, spaces, and one comma. So something like "toronto, ontario" would work. Quote Link to comment Share on other sites More sharing options...
joe92 Posted December 19, 2011 Share Posted December 19, 2011 Can you be a bit more specific please. Are you trying to validate the data to make sure no numbers are passed through? An example input and desired output would be very helpful. Quote Link to comment Share on other sites More sharing options...
crackpanda Posted December 19, 2011 Author Share Posted December 19, 2011 I'm starting a new topic because i need something different now. Quote Link to comment Share on other sites More sharing options...
crackpanda Posted December 19, 2011 Author Share Posted December 19, 2011 I need a regex for letters, spaces, and a comma: "toronto, ontario" == true "abc, 123, abc" == false "asd. #!@" == false Does anyone know how to form the pattern for this? Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 /^[a-z ,]+$/i Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 Given that you had another thread where you asked this exact same question and then said you wanted something different, how about you explain what you mean? Quote Link to comment Share on other sites More sharing options...
crackpanda Posted December 19, 2011 Author Share Posted December 19, 2011 That worked If you look carefully the previous thread asked for a single space. I need to not limit the spaces in my case. Thank you for the expression, epic. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted December 19, 2011 Share Posted December 19, 2011 That was the exact same expression silkfire gave in your other thread, except silkfire forgot the square brackets. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.