Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regular expression and line break problem

807589Jun 22 2008 — edited Jun 22 2008
Hi friends,

I was trying out one regular expression in java but, for some reasons its not working. The test string looks something like this in the eclipse watch window:-

Test string:-*
Content-Disposition: form-data; name="name"\n\nOmkar\n|


In the above test string the last character is a pipe symbol.
And the java code i have written is: -

code:
    public static void getParameterValue(String paramName, String testParameter) {
    		String parameterRegex = "name=\""+paramName+"\"(.*)|";
    		
    		Pattern pattern = Pattern.compile(parameterRegex,Pattern.DOTALL);
    		Matcher matcher = pattern.matcher(testParameter);
    		
    		boolean isFound = matcher.find();
    		if (isFound) {
    			System.out.println("The parameter value is : "+matcher.group(1));
    			
    		}
    	}
After, the debug line moves over the first line in this method, the value contained in the "parameterRegex" string variable is:-

Regex:-*
name="name"(.*)|



However, my SOP statement, prints null....even though, "isFound" variable is true....can someone please explain me what could be the problem, where i am going wrong ?....

I have even, set the DOTALL option for the regex.

please some one help me!

Thanks and Regards
Omkar Patkar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2008
Added on Jun 22 2008
6 comments
487 views