Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 804263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:53:26+00:00 2026-05-14T23:53:26+00:00

I have the following string 3/4Ton. I want to split it as –> word[1]

  • 0

I have the following string “3/4Ton”. I want to split it as –>

word[1] = 3/4 and word[2] = Ton.

Right now my piece of code looks like this:-

Pattern p = Pattern.compile("[A-Z]{1}[a-z]+");
Matcher m = p.matcher(line);
while(m.find()){
    System.out.println("The word --> "+m.group());
    }

It carries out the needed task of splitting the string based on capital letters like:-

String = MachineryInput

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

The only problem is it does not preserve, numbers or abbreviations or sequences of capital letters which are not meant to be separate words. Could some one help me out with my regular expression coding problem.

Thanks in advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:53:27+00:00Added an answer on May 14, 2026 at 11:53 pm

    You can actually do this in regex alone using look ahead and look behind
    (see special constructs on this page: http://java.sun.com/javase/6/docs/api/java/util/regex/Pattern.html )

    /**
     * We'll use this pattern as divider to split the string into an array.
     * Usage: myString.split(DIVIDER_PATTERN);
     */
    private static final String DIVIDER_PATTERN =
    
            "(?<=[^\\p{Lu}])(?=\\p{Lu})"
                    // either there is anything that is not an uppercase character
                    // followed by an uppercase character
    
                    + "|(?<=[\\p{Ll}])(?=\\d)"
            // or there is a lowercase character followed by a digit
    
            ;
    
    @Test
    public void testStringSplitting() {
        assertEquals(2, "3/4Word".split(DIVIDER_PATTERN).length);
        assertEquals(7, "ManyManyWordsInThisBigThing".split(DIVIDER_PATTERN).length);
        assertEquals(7, "This123/4Mixed567ThingIsDifficult"
                            .split(DIVIDER_PATTERN).length);
    }
    

    So what you can do is something like this:

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

    Sean

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following string hello[code:1], world [code:2], hello world I want to replace this
I have following string: ;Spe \,\:\; cial;;; and I want to split it with
I have following String and i want to split this string into number of
I have the following string: \\\\AAA.AA.A.AA\\d$\\ivr\\vm\\2012May\\29\\10231_1723221348.vox I would like it to look like: \\AAA.AA.A.AA\d$\ivr\vm\2012May\29\10231_1723221348.vox
Have the following string i need to split. $string = This is string sample
I have following string task BLABLA@{taskId} @{BLABLA.title} and want to extract all placeholders from
I have following string: xxxxx GL=>G0 yyyyyy I want to extract GL and G0
I have following code: string date = 13.04.2012; string date2 = (DateTime.Parse(date).AddDays(1)).ToString(); This is
I have the following string and i want to derive the number ( 104321
I have the following string : str = {application.root.category.id:2} I would like to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.