0

I need to read a string from the paragraph which has format of "abc.xyz" format. I am very new for regular expression and i am stucked hear to read the format, please can any one help me out to get the data example:

Calendar_year_lookup.Yr,Outlet_Lookup.Shop_name,Article_lookup.Category, Article_lookup.Sale_price, sum(Shop_facts.Quantity_sold)

Output:

 Calendar_year_lookup.Yr    
  Outlet_Lookup.Shop_name  
 Outlet_Lookup.Shop_name
Article_lookup.Sale_price
Shop_facts.Quantity_sold

code:

 public static void main(String[] args)
    {
        // TODO Auto-generated method stub

        String  data="Calendar_year_lookup.Yr,Outlet_Lookup.Shop_name,Article_lookup.Category, Article_lookup.Sale_price, sum(Shop_facts.Quantity_sold)";

        //data.matches("\w\.\w");
        Pattern pattern = Pattern.compile("\\p{L}+[.]\\p{L}+");
        Matcher matchers=pattern.matcher(data);
        //System.out.println(matchers);
        if(matchers.find())
        {
        System.out.println(matchers.group(0));
        }

    }

3 Answers3

1

If I understand your pattern, the regex would be:

"[a-zA-Z]+\.[a-zA-Z]+"

You would have to escape the backslash in java!

LionC
  • 3,106
  • 1
  • 22
  • 31
0

Your regex should be

\\w+[.]\\w+

+ is a quantifier which matches preceding character or group 1 to many times

. can be escaped as \\. or [.]

Now your code would be

while(m.find())
{
    m.group(0);//your value
}
Anirudha
  • 32,393
  • 7
  • 68
  • 89
  • I am unable to read complete data. its cutting please check the updated code –  May 28 '13 at 10:39
  • @Chinna you should use `\w`..check out the edit..with `\\p{L}` you are only matching alphabets..you can also use `[\\p{L}_]` – Anirudha May 28 '13 at 10:40
-2

The following might work

[a-zA-Z].[a-zA-Z]
Pavan Kumar K
  • 1,360
  • 9
  • 11