0

String: 'Purchase Appln : 2157551 - DIRECT 1,23.00 1,234.23'

Output result should be

str1 = 'Purchase Appln : 2157551 - DIRECT';

str2= '1,23.00 1,234.23';

Please help me to create a regex expression to get that desired result.

0

2 Answers 2

1

Use positive lookaround with String.split method:

String input = "Purchase Appln : 2157551 - DIRECT 1,23.00 1,234.23";
String[] result = input.split("(?<=DIRECT) ");
System.out.println(Arrays.toString(result));

Will print that you need

[Purchase Appln : 2157551 - DIRECT, 1,23.00 1,234.23]
Sign up to request clarification or add additional context in comments.

Comments

0

Try

String str = "Purchase Appln : 2157551 - DIRECT 1,23.00 1,234.23";

String str1 = str.substring(0, str.indexOf("DIRECT" + 6); //str1 = 'Purchase Appln : 2157551 - DIRECT';

String str2 = str.substring(str.indexOf("DIRECT" + 7);    //str2= '1,23.00 1,234.23';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.