Reg. Expression doesn't want to stop: /\*((.)*\s)*((\*)/)*

I'm designing a regular expression tester that takes the regular expression in one jtextpane and applies it to the text in another jtextpane.
The following code:
            Pattern pat = Pattern.compile(regExpPane.getText());
            Matcher m = pat.matcher(sdoc.getText(0, sdoc.getLength()));
            while (m.find() )
                doLater(m.start(), m.end()-m.start(), matched, true);
The doLater function is just a thread that applies setCharacterAttributes after the mutex on the styled document has been released.
The regular expression:
/\*((.)*\s)*((\*)/)*throws the while loop into an infinite loop ( I know this from limiting it to 10 cycles or less) when it finds text to match. The regular expression, as some of you may have already guessed, is for highlighting commented code between and including /* ... */
On smaller cases, such as one or two lines, it works fine. The problem arises on larger cases. Why would this run infintely? Perhaps someone has some suggestions for improvement?

Very poor solution...probably doesn't test everything...definitely doesn't test /* inside quotes.
But it might help
/* the first comment */
// standard imports
import java.util.regex.*;
import java.util.*;
import java.io.*;
import java.nio.*;
// import static java.lang.String.format;
// import static java.lang.System.out;
// local imports
public class RegexExample
    private static Pattern SLASH_DOT_PATTERN;
    private static Pattern getSlashPattern()
        if (SLASH_DOT_PATTERN == null)
            String regex = "(?:[^/]|^)  /\\*  (?:[^*]  | \\*[^/])*   \\*/";
            //                     1      2            3               4
            // 1 Either starts at the beginning of the file or not a //* kind of
            // comment.
            // 2 Start of a slash-star comment
            // 3 The stuff inside the slash-dot comment cannot be a star-slash
            // 4 End of a slash-star comment.
            SLASH_DOT_PATTERN = Pattern.compile(regex,
                                                Pattern.DOTALL | Pattern.COMMENTS);
        return SLASH_DOT_PATTERN;
    public static void main(String [] args)
        testCommentInFiles(args);
    private static void testCommentInFiles(String [] filenames)
        Matcher m = getSlashPattern().matcher("");
        for (int i = 0, maxi = filenames.length; i < maxi; i++)
            System.out.println("\n\n----------------\nTesting file: " +
                    filenames);
boolean noMatchWasFound = testFile(filenames[i], m);
if (noMatchWasFound)
System.out.println("No slash star found in this file");
else
System.out.println("\nThat was file: " +
filenames[i]);
try
Thread.sleep(noMatchWasFound ? 1000 : 2000);
catch(InterruptedException ex)
* this is more
* commenting going on.
private static boolean testFile(String filename, Matcher m)
boolean noMatchWasFound = true;
try
File f = new File(filename);
long l = f.length();
int len = l > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)l;
char [] data = new char[len];
FileReader in = new FileReader(f);
in.read(data);
in.close();
CharSequence seq = CharBuffer.wrap(data);
m.reset(seq);
while (m.find())
noMatchWasFound = false;
System.out.println("\nFound match: " + m.start()
+ ":" + m.end());
System.out.println(m.group());
catch(Exception ex)
System.out.println(ex);
return noMatchWasFound;

Similar Messages

  • My iMac doesn't want to stop automatically

    hi! since a month my iMac doesn't stop automatically, I have to use the botton on the back.... Is there anyone can help me?

    sorry what do you mean with +Check the schedule+?
    [IMG]http://img185.imageshack.us/img185/856/monitor1ju8.th.jpg[/IMG]
    [IMG]http://img261.imageshack.us/img261/4562/monitor2jl7.th.jpg[/IMG]
    this is what is working in my activity monitor

  • My charger doesn't want to plug in to the phone,it suddenly stopped working.What should I do?, My charger doesn't want to plug in to the phone,it suddenly stopped working.What should I do?

    My charger doesn't want to plug in to the phone,it suddenly stopped working.What should I do?, My charger doesn't want to plug in to the phone,it suddenly stopped working.What should I do? iPhone 5

    Clean the lint/debris from the charging port and plug the cable in.

  • Do I need a cable connecting my Time Capsule to Airport Express if I want to use the AE to extend my wifi network range?

    I'm a bit confused by conflicting advice given by my local Apple shop and my internet provider. 
    My cable modem is plugged into a Time Capsule which I use to access the net wirelessly almost all over the house.  The one spot the wireless doesn't quite reach is (of course) where I now need my office and iMac to be.
    I thought I could just plug in an Airport Express somewhere in the middle  to extend the network's range but the guy at my local Apple shop said the Airport Express would need to be connected not just to power but to the Time Capsule, via a cable.  That's fiddly and would involve cables running under the floor or along walls and ceilings, not something I can or really want to do.  It's not really practical to try and move the cable connection point either.
    My internet provider suggested a netgear wireless extender and said that would only need to be plugged into power.  The reviews of the netgear product I found comparing it to Airport Express suggest that the Express doesn't need to be connected to anything other than power either to extend a network range (which was what I originally thought).
    So I'm wondering which advice is correct? I've also read that the netgear product isn't all that easy to set up so I'd rather stick with.   Apple if it will do what I want.
    Thanks for any help out there

    I thought I could just plug in an Airport Express somewhere in the middle  to extend the network's range but the guy at my local Apple shop said the Airport Express would need to be connected not just to power but to the Time Capsule, via a cable.
    I'm sure that the guy at the Apple shop means well, but he is not correct. 
    While it would be preferable to connect the Time Capsule and AirPort Express using a wired Ethernet connection, the Express can connect wirelessly and extend the wireless signal the same way....IF...it is located where it can receive a good wireless signal.

  • Airport Express doesn't work with Mountain Lion

    I installed Mountain Lion and now my airport express doesn't work as a way to play itunes through another set of speakers. 
    Not only that... but the airport utility doesn't support my airport express.
    Time Machine doesn't work either....
    I want my snow leopard back!!!
    Any insight????

    I understand that Airport Utility 5.6 must be used to configure it... but that being an older version... I can't install it with the new OS... RRRGGGGGHHHH Mountain Lion!!!  I'm not liking the switch at all.  I've spent more time fixing problems with this ... how can I go back???

  • Just updated to OS X 10.9.3 on iMac. Update restart doesn't want iMac to boot.

    Just updated to OS X 10.9.3 on iMac. Update restart doesn't want iMac to boot. Hanging since. Got a pink screen after update and then hangs at progress indicator. Tried all, also safe mode, and after start up in Safe Mode the indicator spins of 25s, indicator stops spinning and hangs. Been hanging now for 23 minutes...!

    First, Safe Boot , (holding Shift key down at bootup), use Disk Utility from there to Repair Permissions, test if things work OK in Safe Mode.
    Then move these files to the Desktop for now...
    /Users/YourUserName/Library/Preferences/com.apple.finder.plist
    /Users/YourUserName/Library/Preferences/com.apple.systempreferences.plist
    /Users/YourUserName/Library/Preferences/com.apple.desktop.plist
    /Users/YourUserName/Library/Preferences/com.apple.recentitems.plist
    Reboot & test.
    PS. Safe boot may stay on the gray radian for a long time, let it go, it's trying to repair the Hard Drive.

  • CFINPUT Reg Expression Validation Pattern Help

    I've got a form with a non-required field that needs to meet
    some validation requirements (Numbers, Letters, 'space character'
    or 'blank, empty string' only) if the user chooses to fill it
    out...
    I'm using CFINPUT tag with the following settings, does my
    Reg Expression pattern look OK?
    REQUIRED="No"
    VALIDATE="regular_expression"
    PATTERN="^[a-zA-Z *]{1,40}$"
    MAXLENGTH="40"
    Thanks for any help. I'm v. new to regular expressions (10
    hrs education at Google Univ.)
    Sincerely,
    Paul Cross

    I think you want something more like this:
    ^[a-zA-Z0-9 ]{0,40}$

  • Reg expression help

    Can/will you help me make a regular expression for these characters? I want to replace eveyone occurance in a string contianing these chars
    \/:*"<>|
    with
    right now I am doing a string.replaceAll(...) on each char but I was wanting to combine that to one reg expression. What cha got? I am doing this b/c I am generating file names and those are not valid chars allowed in file names.
    Thanks
    Doopterus

      String regex = "[*<>/'\"\\\\]";In a character class (i.e., between the square brackets), "|" has no special meaning.

  • I want to stop my iPhone syncing with iPhoto

    I want to stop my iPhone syncing with iPhoto.
    I find the business of syncing my low-res phone pics with my Mac pointless and time-consuming. I notice that even if you do sync-up - then, unplug phone from Mac and re-plug - it will ask do you want to sync up 22 pics - yes - Hey i can see these are all duplicates shall I not bother it says....
    OR if you dont sync-up at the above - it means you always have to wait for iPhoto to open up and thats annoying too.
    I have unchecked the 'sync with iphoto' option in itunes tabs. But this does not stop the phone from attempting the iphoto sync-up.
    Why you no risson? I say..
    Anyone else had this problem greatful for any fix. Thanks.

    The selection under the Photos tab for your iPhone sync preferences is for transferring photos from your computer to your iPhone via the iTunes sync process.
    When your iPhone includes photos that were captured by your iPhone (stored in your iPhone's Camera Roll), or any photos saved from an email or from a website on your iPhone which are also stored in your iPhone's Camera Roll, you iPhone is also detected as a digital camera when connected to your computer. If you want to import these photos to your computer, you can use iPhoto or the Image Capture application.
    To prevent iPhoto from launching automatically when you iPhone includes photos in the Camera Roll when your iPhone is connected, depending on the iPhoto version you are using, this is done with iPhoto preferences. If your iPhoto version doesn't include this preference setting, you can accompish the same with the Image Capture application - Image Capture preferences. At automatically open with, select No Application.

  • I want to change my iCloud email. My dad doesn't want messages from my iPad to his. How do I change the email?

    My dad has messages from my ipad. He doesn't want the messages that I text. How can I chane the email on the I cloud?

    Simply stop using the same Apple ID for iMessage on both devices.

  • The green light in my airport express started blinking and doesnt stop and I cannot find it anymore

    the green light in my airport express started blinking and doesnt stop and I cannot find it anymore

    Unfortunately, green blinking is usually a symptom of an internal electrical problem on the AirPort Express.
    Try a Factory Default Reset as a last resort:
    Power down the Express
    Wait ai few minutes
    Hold in the reset button first, and keep holding it in for an additional 9-10 seconds while you simultaneously plug it back in to power
    Release the reset button after the hold period and allow a full minute for the Express to restart.
    You want to see a slow blinking amber light at this point, indicating that the Express has been reset to factory defaults. You can reconfigure it again now.
    If you try the Factory Default Reset a few times and this does not help, I am afraid that the Express is defective and will need to be replaced.

  • Ipod 20 Gb click wheel just doesn't want to turn on

    I received my ipod one year ago and till last week I have never had any problems with it.Since last week it just doesn't want to turn on.I have done every step that it is said on the site that i should do in this situation and my ipod still doesn't turn on.When i try to restart it,it shows me the apple icon but it does not go any further.I can't get into my menu not even after I placed it on the Disk mode.I can hear it trying to open but never succeds.What am I supposed to do?And even if I should get it to a Service I don't even know where I could do that in Romania.
    I would appreciate any kind of help.
    Windows   Windows XP Pro  

    Have you seen if these articles help?
    iPod won't turn on
    iPod stops responding or won't wake from sleep
    -Kylene

  • CS3 doesn't want to work any more

    Hello,
    I have an old version of the creative suite that is all right for what I do (information for a charitable organisation for medical research) installed in 2008. For quite a while now every once in a while when I start up I get a screen asking me to register. But since I already am registered Adobe just said to click on later and go on working. But this morning the screen is empty so I can't click anywhere. I've tried restarting and even turning off the computer and trying to restart my day.
    What can I do ? Help !
    Thanks.

    Thanks a lot. That worked for me too. I was afraid that CS3 had changed into
    a pumpkin this morning.
    virginie
    Le 22/11/13 13:25, « De Mostertman » <[email protected]> a écrit :
    Re: CS3 doesn't want to work any more
    created by De Mostertman <http://forums.adobe.com/people/De+Mostertman>  in
    Photoshop General Discussion - View the full discussion
    <http://forums.adobe.com/message/5865197#5865197>
    I had my CS3 freezing this morning on startup. I hope you didn't reinstall or
    anything bacause the sollution is quite simple: What helped me was restarting
    Photoshop with the internet cable pulled out. Apperently it was freezing on
    the registerscreen, and by removing the internet cable I surpassed that
    screen, to see another screen.after that i could start it up again with the
    internet cable plugged in again.
    Please note that the Adobe Forums do not accept email attachments. If you want
    to embed a screen image in your message please visit the thread in the forum
    to embed the image at http://forums.adobe.com/message/5865197#5865197 Replies
    to this message go to everyone subscribed to this thread, not directly to the
    person who posted the message. To post a reply, either reply to this email or
    visit the message page: http://forums.adobe.com/message/5865197#5865197 To
    unsubscribe from this thread, please visit the message page at
    http://forums.adobe.com/message/5865197#5865197. In the Actions box on the
    right, click the Stop Email Notifications link.  Start a new discussion in
    Photoshop General Discussion at Adobe Community
    <http://forums.adobe.com/choose-container!input.jspa?contentType=1&containerTy
    pe=14&container=4694>  For more information about maintaining your forum email
    notifications please go to http://forums.adobe.com/thread/416458?tstart=0.

  • Black Berry curve 9300 3G doesn't want to reboot

    hello all,
    today i decided to delete the facebook app of my blackberry curve 9300, at the end of the process I was asked to restart the phone....but since then the starting process get stopped at about 3/4 of the bar...I waited for several hours but it doesn't want to get fully restarted...I did several restart by taking the battery out and back again without success. I just feel like I lost my phone just because I wanted to remove an application...I tried different things to get the phone back like reloading the OS with the KB1044 but it doesn't work...(it says it doesn't find any update for my phone) I don't know what to do. Can someone help me?

    Start your phone in safe mode and delete the app if still in there. See this article.
    How to start a BlackBerry smartphone in Safe Mode
    Thanks.
    Good luck!
    Please thank those who help you by clicking the button.
    If your issue has been solved, please resolve it by marking "Accept as Solution"

  • I installed Adobe premier on my laptop but it doesn't want to launch.

    I installed Adobe premier on my laptop but it doesn't want to launch. Everytime I try it stops by it

    IF your laptop has dual graphics, read below for ideas on how to force your OS to use the "high power" graphics adapter
    Dual video problems
    -http://helpx.adobe.com/premiere-pro/kb/error---preludevideo-play-modules.html
    -http://forums.adobe.com/thread/1001579
    -Use BIOS http://forums.adobe.com/thread/1019004?tstart=0
    -link to why http://forums.adobe.com/message/4685328
    -http://www.anandtech.com/show/4839/mobile-gpu-faceoff-amd-dynamic-switchable-graphics-vs-n vidia-optimus-technology/2
    -HP Fingerprint/Password conflict http://forums.adobe.com/thread/911575
    -Mac Utility http://forums.adobe.com/thread/1017891?tstart=0

Maybe you are looking for