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

  • SEARCH
  • Home
  • 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 7884347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:46:30+00:00 2026-06-03T04:46:30+00:00

I have a long string that I want to parse and retrieve a value.

  • 0

I have a long string that I want to parse and retrieve a value.
I was thinking of using patterns but I am a bit rusty at this.

This is the part of the string that interests me:

…sinking will be 44% successful…

the word ‘sinking’ is the keyword. I am looking to get the percentage value(44% in this case)

What is the best way?
Thank you.

** the words ‘will be’ may change.

  • 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-06-03T04:46:32+00:00Added an answer on June 3, 2026 at 4:46 am

    Here’s a regex solution:

    String str = "...sinking will be 44% successful...";
    Pattern p = Pattern.compile( "sinking will be (\\S*) successful" );
    Matcher m = p.matcher( str );
    if ( m.find() ) {
        String percent = m.group( 1 );
    }
    

    If you want just the numeral value of the percent, change your pattern to this:

    "sinking will be (\\d*)% successful"
    

    If any of the preceding text is irrelevant, you just want to grab the percent in a line, use this pattern:

    "(\\d*%)"
    

    Edit: If your keyword is “sinking”, and you want the first percentage value after this word, this would be your pattern:

    "sinking(?:[\\w\\s]*) (\\d+%)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an extremely long string that I want to parse for a numeric
I have a simple question. I have a long std::string that I want to
I have a long string, the format will be same of this string but
I have a long string that I want to encode to ascii. I'm doing:
I have a long string that I need to parse into an array of
I have a long string, want to break that string in new line after
I have a Long string from that I want to store the keyword in
I have a long String that I want to display in a JTextField .
I have a long string of comments that I'd like to split into multiple
i have a long string variable and i want to search in it for

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.