NYCPHP Meetup

NYPHP.org

[nycphp-talk] Regular expression in PHP with preg_match using Roman Numerals?

David Roth davidalanroth at gmail.com
Sun Feb 21 22:53:40 EST 2010


Hi Rene.

Thanks so much for posting this solution. I will check it out!

David Roth

On Feb 21, 2010, at 1:20 AM, Rene Samson wrote:

> Hi David,
>
> I've added the roman numerals to your regex, now it will match  
> either just the year (2000) or the year + the roman numeral (2000/I)  
> up to VIII (I know you said it goes up to III, but you never know)
>
> preg_match('/\((19|20)[0-9][0-9](\/(I{1,3}|IV|VI{0,3}))?\)/',$line, 
> $found);
>
> I haven't fully tested it though (did run it on (2000), (2000/I)- 
> (2000/VIII) but that was it).
>
> Also this is still case sensitive, don't know if that matters...
>
> Rene
>
> David Roth wrote:
>> Hi Folks.
>>
>> I didn't come up with this method, I'm just the one who has to deal  
>> with it. :-)
>>
>> The year is represented most of the time in this format:
>>
>> (2000)
>>
>> This regular expression in preg_match to extract it has been  
>> working fine:
>>    preg_match('/\((19|20)[0-9][0-9]\)/',$line,$found);
>>
>> However, other times it is represented with Roman Numeral version  
>> control when there is more than one version:
>>
>> (2000/I)
>> or
>> (2000/II)
>>
>> So far it looks like the version control goes out to three Roman  
>> Numbers. Like I said, I didn't come up with this.
>>
>> It would be just peachy if some kind person here could show me an  
>> elegant way to handle this in PHP (as a regular expression?) which  
>> might  be, for example, either (2000) or (2000/V). Thanks in advance!
>>
>> David Roth




More information about the talk mailing list