regex - split a string based on pattern in java - capital letters and numbers -


I have the following string "3/4 ton" I have it ->

the word [1] = 3/4 and the word [2] = I want to split into ton.

This code of my code looks like this now: -

Patterns p = Pattern.compile ("[AZ] {1} [az] +"); Mitcher M = P. Dead line (line); While (m.find ()) {System.out.println ("word ->" + m.group ()); }

This works essential to split the stratification by capital letters like: -

string = machinery input

[1] = Machinery, word [2] = input

The only problem is that it does not sequence numbers, sequence numbers or abbreviations or capital letters, which are not individual words. Can anyone help me with my regular expression coding problem?

Thank you in advance ...

You actually look at it further and behind You can do this by viewing Rejeks alone (see Special Structures on this page).

  / ** * We will use this pattern as a divider * Use to split the string into an array : MyString.split (DIVIDER_PATTERN); * / Personal static last string DIVIDER_PATTERN = "(? & Lt; = [^ \\ p {lu}]) (? = \\ p {lu})" // Either there is anything that is not an uppercase character / Is an uppercase letter + "| (?? (? & Lt; = [\\ p {Ll}]) (? = \\ d)" // or a small letter that has been made after a number; @Test Public Zero Test Stringing () {Attempt to push (2, "3/4 word" .split (DIVIDER_PATTERN). Length); Emphasis (7, "many many words inbuilt" .split (DIVIDER_PATTERN). Length); AssertEquals (7, "It 123/4Mixed567ThingIsDifficult" .split (DIVIDER_PATTERN). Length); }  

Then you can do something like this:

 for  (string word: myString.split (DIVIDER_PATTERN)) {System.out.println ( word); }  

Sean


Comments