Results 1 to 4 of 4
  1. #1
    asheshrocky is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default URGENT HELP : Java Regular Expression

    Hi All,

    This is my first post with this forum.
    I have a situation where am stuck with the Pattern matcher to compile my regular expression.

    I have a formula to be parsed as below :

    Java Code:
    APDM_ABS_LT_WL-A+WL_BL|APDM_ABS_LT_WL-A+WL_BL|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|1.00E+20|abs(if((x1 = 1 || x1 = 2), y = 0, y=1))
    This is my code snippet:

    Java Code:
    	private void genDisWithCalPara(File calParaFile) {
    		ArrayList<String> calParaNameAL = new ArrayList<String>(500);
    		ArrayList<String> calPara4LimitDisAL = new ArrayList<String>(500);
    		ArrayList<String> calParaFormulaAL = new ArrayList<String>(500);
    
    		try{
    			//If the constructor throws an exception, the finally block will NOT execute
    	
    			BufferedReader reader  = new BufferedReader(new FileReader(calParaFile));
    			Pattern pattern = Pattern.compile("(.*)(\\|.*\\|.*\\|.*\\|.*\\|.*\\|.*\\|.*\\|.+\\|)(.*)");
    			Matcher matcher = null;
    
    			try{
    				String aLine = null;
    				while((aLine=reader.readLine()) != null){
    	System.out.println(aLine);
    					matcher = pattern.matcher(aLine);
    					if (matcher.find()){
    						System.out.println("g(1)="+matcher.group(1));
    						System.out.println("g(2)="+matcher.group(2));
    						System.out.println("g(3)="+matcher.group(3));
    						calParaNameAL.add(new String(matcher.group(1)));
    						calPara4LimitDisAL.add(new String(matcher.group(2)));
    						calParaFormulaAL.add(new String(matcher.group(3)));
    					}//end if
    					continue;
    				}//end while
    			}finally{
    				reader.close();
    			}//end finally
    		} catch (Exception e){
    			JNotify.getInstance().log(JNotify.ERROR,"000"
    					, "JCalPara.genDisWithCalPara"
    					, "ConfigFileNotFound"
    					, JNotify.getStackTraceString(e)
    				);
    			System.exit(1);
    		} //end catch
         try {
    		if (calParaNameAL.size() > 0){
    			createDatawcalDIS(calParaNameAL,calParaFormulaAL);
    			createLimitwcalDIS(calParaNameAL,calPara4LimitDisAL);
    		}
         }
         catch (Exception e){
    			JNotify.getInstance().log(JNotify.WARN,"000"
    					, "JCalPara.genDisWithCalPara"
    					, "calParaNameAL is Empty"
    					, JNotify.getStackTraceString(e)
    				);
         }
    			System.exit(1);
    	}
    Ok now the problem i am facing is that i am not able to get the required result with the currently used Pattern.compile.
    Whenever i have an OR (||) symbol in the forumula (if((x1 = 1 || x1 = 2), y = 0, y=1)),it shows me an different result as it read || symbol as pipe(|) and not as logical OR .

    When i run above i get the following output:

    Java Code:
    APDM_ABS_LT_WL-A+WL_BL|APDM_ABS_LT_WL-A+WL_BL|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|1.00E+20|abs(if((x1 = 1 || x1 = 2), y = 0, y=1))
    g(1)=APDM_ABS_LT_WL-A+WL_BL|APDM_ABS_LT_WL-A+WL_BL
    g(2)=|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|1.00E+20|abs(if((x1 = 1 ||
    g(3)= x1 = 2), y = 0, y=1))

    Expected Result should be like :

    Java Code:
    APDM_ABS_LT_WL-A+WL_BL|APDM_ABS_LT_WL-A+WL_BL|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|1.00E+20|abs(if((x1 = 1 || x1 = 2), y = 0, y=1))
    g(1)=APDM_ABS_LT_WL-A+WL_BL
    g(2)=|APDM_ABS_LT_WL-A+WL_BL|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|-1.00E+20|1.00E+20|1.00E+20|
    g(3)=abs(if((x1 = 1 || x1 = 2), y = 0, y=1))
    Please help me to achieve the same...

    Regards
    Ashesh
    Last edited by asheshrocky; 12-07-2011 at 06:06 AM.

  2. #2
    asheshrocky is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: URGENT HELP : Java Regular Expression

    Any suggestions experts ?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: URGENT HELP : Java Regular Expression

    Quote Originally Posted by asheshrocky View Post
    Any suggestions experts ?
    Yes

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    asheshrocky is offline Member
    Join Date
    Dec 2011
    Posts
    6
    Rep Power
    0

    Default Re: URGENT HELP : Java Regular Expression

    did you find something wrong with my post ?
    I just tried to brief my problem.....it would be difficult to just explain in words i guess.

Similar Threads

  1. Java regular expression optimization - help needed
    By dpkcv in forum Advanced Java
    Replies: 0
    Last Post: 09-30-2011, 08:42 AM
  2. Replies: 2
    Last Post: 06-17-2010, 12:44 PM
  3. Java Regular expression ?
    By sidharth in forum Advanced Java
    Replies: 12
    Last Post: 11-14-2009, 11:09 AM
  4. Java Regular Expression help
    By royalibrahim in forum Advanced Java
    Replies: 11
    Last Post: 11-12-2009, 01:27 AM
  5. Replies: 2
    Last Post: 11-11-2009, 05:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •