Japanese regular expressions!

  • Thread starter Thread starter tim
  • Start date Start date
T

tim

Hi there!

I am in Japan right now fiddeling with an JP to AD date change program, for
this I have constructed one block where the date is inputted, and which
decides wether it will go to the AD to JP, or JP to AD change block.. Like
so:

public string ChangeDate(string tmpDate)
{
Match
m=Regex.Match(tmpDate,"^(19[0-9][0-9]|20[0-9][0-9])[/.]([0]{0,1}[1-9]|1[012])[/.]([0]{0,1}[1-9]|[12][0-9]|3[01])$");

Match
o=Regex.Match(tmpDate,"^\\Id*[1-9][0-9]\\Id([0]{0,1}[1-9]|1[012])\\Id([0]{0,1}[1-9]|[12][0-9]|3[01])\\Id$");
string retValue = "";

if (m.Success==true) //If tmpDate is AD Date.
{
retValue = this.GetJpDate(Convert.ToDateTime(tmpDate));
if (retValue != null)
return retValue;}
else if (o.Success==true) //If tmpDate is JP Date.
{
retValue = this.GetAdDate(tmpDate).ToString("yyyy/MM/dd");
if (retValue != null)
return retValue;}
else
{
throw(new Exception());}
return retValue;
}

A Japanese date is constructed like so: $BJ?@.(B12$BG/(B12$B7n(B12$BF|(B, and here is the
problem, I can not "Match o" to work (return true), even if I match to a
single Kanji character, I cannot get a match! How do I match Kanji
characters, I tried every ms solution I could find.

Can anybody help me with this dilemma?

Tim
 
Christ!
Japanese is complicated enough! So are regular expressions.

But *japanaese regular expressions* !

Rather you than me!
 
Have you tried matching for a unicode control code?
Like: Regex.Match(tmpDate, @"\1234") - which should match for the unicode
character with the code 1234. I always thought that would work for any kind
of character.

Niki
 
Hi Niki!

Thanx, yes I have, the problem is that will only work untill the present
Japanese Era, when a new one begins, (new Emporer takes over) the name of
the Era changes and the program becomes obsolite, so I need an expression
that will represent all JP chars. Any Ideas??

Tim


Niki Estner said:
Have you tried matching for a unicode control code?
Like: Regex.Match(tmpDate, @"\1234") - which should match for the unicode
character with the code 1234. I always thought that would work for any
kind of character.

Niki

tim said:
Hi there!

I am in Japan right now fiddeling with an JP to AD date change program,
for this I have constructed one block where the date is inputted, and
which decides wether it will go to the AD to JP, or JP to AD change
block.. Like so:

public string ChangeDate(string tmpDate)
{
Match
m=Regex.Match(tmpDate,"^(19[0-9][0-9]|20[0-9][0-9])[/.]([0]{0,1}[1-9]|1[012])[/.]([0]{0,1}[1-9]|[12][0-9]|3[01])$");

Match
o=Regex.Match(tmpDate,"^\\Id*[1-9][0-9]\\Id([0]{0,1}[1-9]|1[012])\\Id([0]{0,1}[1-9]|[12][0-9]|3[01])\\Id$");
string retValue = "";

if (m.Success==true) //If tmpDate is AD Date.
{
retValue = this.GetJpDate(Convert.ToDateTime(tmpDate));
if (retValue != null)
return retValue;}
else if (o.Success==true) //If tmpDate is JP Date.
{
retValue = this.GetAdDate(tmpDate).ToString("yyyy/MM/dd");
if (retValue != null)
return retValue;}
else
{
throw(new Exception());}
return retValue;
}

A Japanese date is constructed like so: $BJ?@.(B12$BG/(B12$B7n(B12$BF|(B, and here is the
problem, I can not "Match o" to work (return true), even if I match to a
single Kanji character, I cannot get a match! How do I match Kanji
characters, I tried every ms solution I could find.

Can anybody help me with this dilemma?

Tim
 
tim said:
Hi Niki!

Thanx, yes I have, the problem is that will only work untill the present
Japanese Era, when a new one begins, (new Emporer takes over) the name of
the Era changes and the program becomes obsolite, so I need an expression
that will represent all JP chars. Any Ideas??

Oh, I see. Interesting calendar. Can't you match for a character range then
(like [\1234-\2345])? What kind of characters are these, i.e. do they have a
common unicode character class? Do you know how many characters to expect,
could you maybe just use something like [^0-9]{3}?

Niki
 
Back
Top