English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Can some one make me a regular expression that matches this type of string "test,test,test,test," where there is a word then a comma, then another word and a comma, and so on. But if the string is not setup EXCATLY like that it will not match at all (that means a part of it can't match, it has to be all or nothing).

MUCH thankx in advanced for anyone who is able to create this expression for me, I really need it! :-)

2007-01-22 09:13:39 · 5 answers · asked by retrogamer4ever 3 in Computers & Internet Programming & Design

5 answers

try this:
/^([\w']+,)+$/

The apostrophe is there so you can match words like "won't". Omit if you don't care about that.
Added: I forgot that the \w class includes the underscore; if you don't want that, use [a-zA-Z]. So to match only groups of letters followed by single commas, it's ^([a-zA-Z]+,)+$. I should probably mention that the ^ and $ are there to disallow non-matching characters at the beginning and end of the string.

2007-01-22 09:33:15 · answer #1 · answered by injanier 7 · 0 0

We have two solutions here:
   1.   (([a-zA-Z]*)+,){X}
   2.   (([a-zA-Z]+)+,){X}

Where X is the number of repetitions of the pattern. (in your example, X should equ. 4)

The first one, will detect null strings as well, i.e. ",,,,"
The second one, will only detect non-empty strings, like the example you mentioned.

Thanks.

2007-01-22 18:04:30 · answer #2 · answered by Fox 3 · 0 0

[[A-Za-z]+,]+


should do the trick if not search regular expressions on line and that should help

RJ

2007-01-22 17:25:00 · answer #3 · answered by Anonymous · 0 0

I don't know the answer but you can find lots of tools here which may help you: http://www.regular-expressions.info/tools.html

2007-01-22 17:21:31 · answer #4 · answered by MSA 2 · 0 0

do you mean a semi-colon

;

2007-01-22 17:22:47 · answer #5 · answered by invisible 4 · 0 0

fedest.com, questions and answers