View Full Version : regex search for roman numerals


Blurr
12-16-2009, 04:32 PM
I'll preface this by saying that this is the first time I've used regex.

using the expression

//h:b[re:test(., '\bX{0,2}V?I{0,3}V?X?\b')]

to search for roman numerals but it's still picking up words with an I in them like CHOICE or HOLIDAY. shouldn't the word boundry \b markers take care of that, or do they not "collapse" in when no X or V is found?

there may be a better and more efficient way to do this, but like I said, this is one of the first regex lines I've written.

Thanks

kovidgoyal
12-16-2009, 04:36 PM
Easier to use


'[XVIL]+'


which makes use of the fact that there are no (or very few) words made up only of the letters X,V,I or L

Blurr
12-16-2009, 04:55 PM
Heh, wow, just a tad more efficient. Still needs the \b markers though or it picks up words with an I in them. Thanks.