472,110 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Japanese regular expressions!

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

Nov 16 '05 #1
4 5952
Christ!
Japanese is complicated enough! So are regular expressions.

But *japanaese regular expressions* !

Rather you than me!
"tim" wrote:
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: 平成12年12月12日, 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

Nov 16 '05 #2
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" <ti*@chiikikagaku.co.jp> wrote in
news:OQ**************@TK2MSFTNGP15.phx.gbl...
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

Nov 16 '05 #3
tim
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" <ni*********@cube.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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" <ti*@chiikikagaku.co.jp> wrote in
news:OQ**************@TK2MSFTNGP15.phx.gbl...
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



Nov 16 '05 #4
"tim" <ti*@chiikikagaku.co.jp> wrote in
news:ev**************@TK2MSFTNGP09.phx.gbl...
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
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
1 post views Thread by Sven Hanefeld | last post: by
2 posts views Thread by Sehboo | last post: by
4 posts views Thread by Egyd Csaba | last post: by
7 posts views Thread by Billa | last post: by
13 posts views Thread by Wiseman | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.