1

I need to extract the extract this string as 2 document example   test(s): testing one is example and the other is testing ...please tell me how can i extract it...

2 Answers 2

1

You can use String.split() method to split the function to split words from sentence.

Example.

String sentence = "example tests(s): testing";
String[] words = sentence.split(" ");

for (String word: words) {
   system.out.println(word);
}

Found the example here: http://blog.codebeach.com/2008/03/split-string-into-words-in-java.html

Sign up to request clarification or add additional context in comments.

Comments

0

Generally, you want to first come up with a pattern to match your input. Once you do that, and if the pattern doesn't do it already, simply put (...) brackets around the pattern that matches the part you're interested in. This creates what is called capturing groups.

With java.util.regex.Matcher, you can get what each group captured using the group(int) method.

References


Example

Given this test string:

i have 35 dogs, 16 cats and 10 elephants

Then (\d+) (cats|dogs) yields 2 match results (see on rubular.com)

  • Result 1: 35 dogs
    • Group 1 captures 35
    • Group 2 captures dogs
  • Result 2: 16 cats
    • Group 1 captures 16
    • Group 2 captures cats

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.