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 8094249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:44:33+00:00 2026-06-05T20:44:33+00:00

I have a String that looks like this String = Förpackning Flaska (375 ml)

  • 0

I have a String that looks like this

String = "Förpackning Flaska (375 ml) Förslutning Skruvkapsyl Kr/lit (104,00) Pris 39,00 kr Antal i butik 30 st Hyllplats 04-11-01 Förpackning Flaska (750 ml) Förslutning Plastkork/syntetkork Kr/lit (100,00) Pris 75,00 kr Antal i butik 16 st Hyllplats 02-03-01";

I want to extract some of the text inside this string.
The end result I want is this:

“Förpackning Flaska (375 ml) Antal i butik 30 st Förpackning Flaska (750 ml) Antal i butik 16 st”.

I can use the following code:

    name = name.replace(name.substring(name.indexOf(") ") + 2, name.indexOf("Antal")), "");
    name = name.replace(name.substring(name.indexOf("st ") + 2, name.lastIndexOf("")), "");

That will give me this result:

“Förpackning Flaska (375 ml) Antal i butik 30 st”

It basically does what I want it to do, but it stops after the first occurance of the pattern.

I have tried to use a regex pattern but I can’t get it to work. From observing the string, I have concluded that I need a regex pattern that matches everything between “) ” and “Antal”. I will also need to remove the other clutter, but that is easy. My problem is that I can’t seem to get my regex to work, and that would probably be the best way to do something like this. I know that I have to escape the paranthesis to make it a literal character in my regex, but I just can’t get it to work.

This is the regex I’ve come up with and tried:

    Pattern p = Pattern.compile("\b\\) (.+?)\bAntal");
    Matcher m = p.matcher(name);
    m.find();
    System.out.println(m.group(1));

Any help and ideas are welcome!

  • 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-05T20:44:35+00:00Added an answer on June 5, 2026 at 8:44 pm

    This can be done in one line!

    It looks like you want to remove:

    • the next two words after the word "st", and
    • everything between ")" and "Antal"

    Here’s the code that will do that:

    input.replaceAll("((?<= st)( [^ ]+){2}|(?<=\\)).*?(?= Antal))", "");
    

    Notes regarding the regex:

    • I noticed you coded a word boundary as "\b". This is a mistake – you cded a literal backspace. Instead, you code it as "\\b"
    • I’ve used a regex OR expression (A|B) to match both in one regex
    • Both regexes use a look-behind to make the replacement text a blank, which is cleaner than matching part of the input you want to keep, then putting it back, and it meant I coudl combine both regexes into one OR expression
    • the ? in ".*?" is important – it means a non-greedy match. Without it, it will match the first bracket and the last Antal, skipping over any Antal between

    Here’s some test code:

    public static void main(String[] args) {
        String input = "Förpackning Flaska (375 ml) Förslutning Skruvkapsyl Kr/lit (104,00) Pris 39,00 kr Antal i butik 30 st Hyllplats 04-11-01 Förpackning Flaska (750 ml) Förslutning Plastkork/syntetkork Kr/lit (100,00) Pris 75,00 kr Antal i butik 16 st Hyllplats 02-03-01";
        String clean = input.replaceAll("((?<= st)( [^ ]+){2}|(?<=\\)).*?(?= Antal))", "");
        System.out.println(clean);
    }
    

    Output:

    Förpackning Flaska (375 ml) Antal i butik 30 st Förpackning Flaska (750 ml) Antal i butik 16 st
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that looks like this: 9/1/2009. I want to convert it
i have a string that looks like this: sodjfoisdfsdf sdofij sodiosifosf fsdi a123 sdfoi
I have a huge string that looks like this: Text Text Text Text Text
I have a JSON string that looks like this: { package1: { type: envelope,
I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want
I have a method that looks like this: public static String escape(String text) {
Assume I have a class that looks like this: class Sample { public string
If I have a HashMap that looks like this: HashMap<String, MyObject> where the String
I have a plist that looks like this: <dict> <key>Aaron</key> <dict> <key>number</key> <string>1234</string> <key>country</key>
I have some code that looks like: static const std::string and( AND ); This

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.