I
iksrazal
I'm having a hard time combining java string literals, character
escapes newline/carriage returns and regular expressions.
I have a situation where on a particular socket call this string
indicates EOF: Using linux od -c :
0000000 ( P D T ) \r \n # \n
0000011
So the PDT can change. I'd like to match on ') \r \n # \n'
Can someone help me get this code to work? I'm trying to match from
end of line ') \r \n # \n'
import java.util.*;
import java.io.*;
import java.util.regex.*;
/**
*/
class Reg
{
public static void main(String args[])
{
try
{
Reg rn = new Reg();
rn.doWork();
System.out.println("\n\nDone");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void doWork()
{
try
{
CharSequence inputStr = "any_garbage_here)\r\n#\n";
String patternStr = "\\(\\#$";
// Compile with dotall enabled
Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL);
Matcher matcher = pattern.matcher(inputStr);
boolean matchFound = matcher.matches();
if (matchFound)
{
System.out.println("\n\nMatch!");
}
else
{
System.out.println("\n\nNO Match!");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
iksrazal
escapes newline/carriage returns and regular expressions.
I have a situation where on a particular socket call this string
indicates EOF: Using linux od -c :
0000000 ( P D T ) \r \n # \n
0000011
So the PDT can change. I'd like to match on ') \r \n # \n'
Can someone help me get this code to work? I'm trying to match from
end of line ') \r \n # \n'
import java.util.*;
import java.io.*;
import java.util.regex.*;
/**
*/
class Reg
{
public static void main(String args[])
{
try
{
Reg rn = new Reg();
rn.doWork();
System.out.println("\n\nDone");
}
catch (Exception e)
{
e.printStackTrace();
}
}
public void doWork()
{
try
{
CharSequence inputStr = "any_garbage_here)\r\n#\n";
String patternStr = "\\(\\#$";
// Compile with dotall enabled
Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL);
Matcher matcher = pattern.matcher(inputStr);
boolean matchFound = matcher.matches();
if (matchFound)
{
System.out.println("\n\nMatch!");
}
else
{
System.out.println("\n\nNO Match!");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
iksrazal