java regular expression
Hi
I am using java regular expression to evaluate some string
and it works fine with me when the pattern is english but when the pattern contains arabic character it is not working at all what I can do
here is my code
String dayPattern="(الأول|الثاني|الثالث|الرابع|الخامس|السادس|السابع|الثامن|التاسع|العاشر)";
Pattern p = Pattern.compile(dayPattern);
String s="الأول sمن شهر حزيران";
Matcher m = p.matcher(s);
StringBuffer sb =new StringBuffer();
while (m.find()){
m.appendReplacement(sb,"date");
System.out.println( m.group());
}
any help I will be thankful
[1293 byte] By [
javadudea] at [2007-10-2 23:24:11]

Are you expecting to print out the arabic result on the console? In general your console will not have the required font. You will need a viewer that has a font that will display the arabic!
A simple Swing test harness that displays the matches
import java.awt.*;
import javax.swing.*;
import java.util.regex.*;
public class Fred503 extends JPanel
{
public Fred503()
{
super(new GridLayout(0,1));
setPreferredSize(new Dimension(200, 100));
String dayPattern="(الأول|الثاني|الثالث|الرابع|الخامس|السادس|السابع|الثامن|التاسع|العاشر)";
Pattern p = Pattern.compile(dayPattern);
String s="الأول sمن شهر حزيران";
Matcher m = p.matcher(s);
while (m.find())
{
String found = m.group();
JLabel label = new JLabel(found);
label.setFont(new Font("Dialog", Font.PLAIN, 20));
add(label);
}
}
public static void main(String[] args)
{
JFrame frame = new JFrame("Fred503");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Fred503());
frame.pack();
frame.setVisible(true);
}
}
I think you messunderstands me
I do not want to write arabic to cobsole window
My problem
is using unicode character in regular expression
I want some one who know h to use regular expression
I wantto build regular expression to find written number in arabic text
thanx
> I think you messunderstands me
I now don't undestand at all!
>
> I do not want to write arabic to cobsole window
>
> My problem
> is using unicode character in regular expression
> I want some one who know h to use regular
> expression
I know how to use regular expressions so what is it that you are trying to do with a regular expression?
>
> wantto build regular expression to find written
> number in arabic text
This did not come accross from your orignal post. You implied that the regex was not finding a match because you could not see the result on the console. I showed that the result was not visible because your viewer did not have a font that could display arabic. I showed that your regex found something and I showed how the result could be viewed.
Regex yes, arabic no. If I need to be able to read arabic then I am not your man.
hi i have read your post guys and i have a problem regarding arabization.here is my problem when i try to add a record to my DB ,the operation is successfull and the record is added using a SQL statement ,anyway when i restart my applicaiton in netbeans it shows ? instead of showing the original arabic text.this is my first problem ,the second problem is i have hardcoded some of my GUI component's names as arabic Strings,the same previous problem occurs ,and when i try to print to console an arabic sentence it displayed ? ,although i have Arabic (Egypt) the default for displaying non unicode text and i have all arabic encodings installed but my default language is English (United States).so what did happen to my original arabic text? ,what should i do to display them as arabic text ? and how can i get back my arabic strings from ? to the original arabic text.
sorry for the long post.
thanks.