regular expression assistance

Posted on 2006-04-02
Last Modified: 2010-04-17
I need help constructing a regular expression for a String.split method in java.

Basically it needs to split around the +, -, /, and * operators. The catch being it needs to include those operators in the output array.

So for example "52+y*10".split(regex) = {"52", "+", "y", "*", "10"}

I have thought about possibly running two split methods and combining the results, but this is a last resort.

I really have no idea how to approach this, any information sources which could help would be appreciated.

Question by:adam8
    LVL 37

    Accepted Solution

    In PHP, you can do this:

        $str = "52+y*10";

    There should be something similar in Java...

    LVL 1

    Author Comment

    thanks, i'll give it a go.
    LVL 1

    Author Comment

    Thanks, this really halped me. I was trying to use the split method, but I didn't even think about checking for matches.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now