Java regex stop after first occurrence

When using code like the following:
while (matcher.find()) {
string1=matcher.group(1).trim();
System.out.println(charset);
the program goes on looking all through the input string and prints out the final match.
What should be done to find the first occurrence and to stop searching through the input string after the first match has been found? i.e. I want to exit the while loop after the first match is found.

The first .* in your regex matches as much as it can at first, and becuase you used the DOTALL flag, it's able to gobble up the whole remaining string. Then it starts backtracking, trying to match the rest of the regex, and it has to backtrack almost all the way to beginning of the string again before it gets back to the META tag where it's supposed to match (unless it finds a false match elsewhere first). That's just an example of greedy quantifiers at work; by calling it a loop you sent us all barking up the wrong scent trail.
Making that dot-star reluctant is not the solution though; the regex would then match everything from the first occurrence of "<meta" to the first occurrence of "charset", where "charset" could be in a separate META tag or just hanging loose later in the string. Getting rid of the DOTALL flag might restrict the match to just one META tag, but you can't count on that. Try this: REGEX = "<meta\\s[^<>]*?charset=([^\\s\"]+)";
pattern = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE); // the only flag you need{code} Also, if you aren't familiar with this website, you'll probably find it useful:
http://www.regular-expressions.info/                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to stop  after first loop operation  over?

    Hi friends.
    How to stop  after first loop operation  over?
    I have a loop operation in module pool program.
    After first loop over I want to stop.
    I used the STOP keyword, but it is going to dump.
    Thanking you.
    Regards,
    Subash

    Hey,
    The statement STOP is forbidden in methods and, since release 6.10, leads to an uncatchable expection during the processing of screens called with CALL SCREEN...
    As they said above, use a EXIT statement to fix this DUMP...
    Regards,
    Diogo Carvalho

  • Call export with java function stop after a time

    Hi
    we make a function java for call exp.exe.
    We pass at java's function a string
    we use this code
    /* * ExecuteCmd.java * This is a sample application that uses the Runtime Object * to execute a program. * */
    /* Import the classes needed for Runtime, Process, and Exceptions */
    import java.lang.*;
    //import java.lang.Process;
    import java.io.*;
    //import java.lang.InterruptedException;
    class ExecuteCmd {
    public static int Cmd(String args) {
    try {
    /* Execute the command using the Runtime object and get the
    Process which controls this command */
    Process p = Runtime.getRuntime().exec(args);
    /* Use the following code to wait for the process to finish
    and check the return code from the process */
    try {
    p.waitFor();
    /* Handle exceptions for waitFor() */
    } catch (InterruptedException intexc) {
    //System.out.println("Interrupted Exception on waitFor: " + intexc.getMessage());
         return -1;
    return p.exitValue();
    /* Handle the exceptions for exec() */
    } catch (IOException e) {
    // System.out.println("IO Exception from exec : " + e.getMessage());
    // e.printStackTrace();
         return 1;
    after a time the export begin but stop after some time.
    If the schema is little like not table but some sequence the export gone normally but if the schema is big the export stop after a time but we dont have a trace with log.
    Can you help

    I think you need to gobble up the output from the command you are exec'ing. If the exec'd command fills up your command space buffer it will stop when the buffer is full.
    Try adding the lines
    String s = new String();
    while ((s = p.readLine())!=null)
    after the try block to gobble up the output from your command call.

  • Why Does Movie Stops After First Clip?

    I created an iMovie from about 20 clips but once saved the movie stops after the first clip. How do I get it to run full length without having to insert Transitions?

    BlueMovie,
    It sounds like you only have the first clip selected (highlighted in blue).
    Click somewhere above the timeline so that no clips are selected. Now your movie should play in its entirety.
    Matt

  • Java? Stopping after criteria has been met?

    Hi, I have this piece of code I have written;
    num2 = Integer.parseInt(JOptionPane.showInputDialog("Enter second number"));
    if (num1<0){
    negative = ("You have entered a negative number!");
    JOptionPane.showMessageDialog (null, negative);
    num3 = Integer.parseInt(JOptionPane.showInputDialog("Enter third number"));
    if (num1<0){
    negative = ("You have entered a negative number!");
    JOptionPane.showMessageDialog (null, negative);
    if ((num1 == num2) && (num1 == num3))
    result = ("Your triangle is equalateral, all sides are the same length!");
    JOptionPane.showMessageDialog (null, result);
    Everytime the user enters a negative number a message pops up saying "You have entered a negative number" BUT then it goes onto the second string and then third string.
    I have 3 strings, e.g.
    String 1 -> User enters 10
    String 2 -> User enters -19 = You have entered a negative number
    String 3 -> User enters 99
    How can I get the program to stop after the "You have entered a negative number message? Thanx.

    Hi,
    How can I get the program to stop after the "You have entered a negative number message?{code}
    If you want to terminate the currently running jvm use
    {code}
    System.exit(0);
    {code}
    Thanks                                                                                                                                                                                                                                                                                                                                                                                                               

  • MDT 2013 Windows 8.1 Task sequence Stops After first Reboot. login

    Hi There,
    The issue I am having is that After the OS gets laid down, and the Windows 8.1 computer reboots, The task sequence does not continue. It fails everytime. There are not any obvious errors that happen in the process that I can see in the logs. But I have
    customized this process quite a bit and I could use some help. We are deploying potentionally to over 30,000 computers.
    The test machine I have been using is the Surface pro 2.
    The interesting part is after a failure is if I start the process over again ,  boots into PE, then run diskpart manually from command prompt to Clean Disk 0, and then reboot and start the MDT task sequence, it will deploy fine.
    I also have a custom step that copies the TS media from the stick to a Recovery partition I create. The user can launch a -re-image or MDT refresh from an Icon/script, which will unhide this "recovery partition", and kick off a lite touch refresh.
    This works succesfully everytime. We have remote locations with very slow links, so MDT over the network or MDT integrated with SCCM is not an option at this time. So this is the solution.
    I am attempting to use MDT 2013 to deploy Windows 8.1 Offline, and using GPT partitions.
    I am using a custom Format and partiition Step, that call the CustomDiskpart.txt script from %deployroot%\Scripts.
    I am also using a Split image, as multi partitioned EFI/NTFS USB sticks are not a possibility for us , also, the USB sticks capable of this are seen by MDT as a "fixed drive" anyways. Which can cause issues in itself. So the LTIAPPLY.wsf has
    been edited to search and apply ther split .swm files.  This works well.
    After the Task sequence failure I have tried launching the Litetouch scripts from the C:\MINNINT folder manually to continue the sequence, but it doesnt  do anything.
    I don't want to always be running Diskpart manually before imaging a new OEM computer. I needa second pair of eyes on this.
    Thank You in advance!

    Hi,
    Thanks Again for taking a look.
    I checked the sysprep log in the image and they look fine. No errors.
    As requested here are some logs. Let me know if I can provide anything else.
    BDD.log
    litetouch.log
    SMSTS.log
    Im not actually attempting to provide a recovery image. What I am doing is leveraging MDT to refresh the computer remotely. We can update the MDT media on the hidden data partition,when required and kick it off remotely. Some of the computers are very
    remote, and without SCCM DP's, plus a combination of slow links and a lack of deskside techs made this a requirement. This works without incident.
    The only issue I have is on a new computer if I run the sequence (offline USB media) it will fail the first time, unless I run a diskpart clean in PE first.. Then it will succeed. Refreshing the computer is fine.

  • In New iTunes how do I play a whole album - stops after first song

    In iTunes 11.0.1 (12) I select Music in upper left of window, select Albums, click on an album, click on > to play and get the first song and then it stops.

    Make sure Preferences, General, View (Edit > Preferences on PC) "Show list checkboxes" isunchecked.
    Albums will then play normally then by just clicking them in Songs or Albums views.

  • Slides in Simulation Stop After First Slide

    After I published a training video as a swf file in Captivate 5, it only plays the first of 193 slides. It does not automatically move forward to the next slide with audio. What am I doing wrong?

    Hi all
    Hopefully Lilybiri will forgive my intrusion into her thread.
    From what I'm seeing it would appear that during recording you selected both Demonstration as well as Simulation modes. You also mention FMR, but because things are pausing and you don't want them to, I'll assume you aren't talking about FMR here.
    Note that when you choose multiple modes of recording, you are creating multiple projects. A demonstration does just that. Plays through as you are seeming to want. No pausing. A simulation pauses as it attempts to provide a simulated experience for your end user.
    It sounds like Captivate is presenting the Simulation first. You are seeing this and assuming it's the only project? Look at the tabs when you finish. There should be more than one. One should be a Demo and the other a Simulation. If you have closed things and restarted Captivate, look at your recent projects list. You should see the Demonstration there.
    Hope this helps more than hinders... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • HP 2550 Color Laser Jet stops after first page

    I've uninstalled the old drivers and reinstalled new ones for Snow Leopard, but my 2550 crashes after printing page 1 of a document from any of several programs. The red alert light comes on, as if there were a paper jam (there isn't). I have to open and close the front door and wait while it goes through its startup routine. Then it may print page 2 only to crash again, or it may simply crash without printing anything. Is anybody else experiencing anything like this with HP printers?
    I have to say, I totally regret installing Snow Leopard. My Adobe CS3 programs crash regularly (Premiere is almost unusable). QuickTime Player X and Player 7 (you have to have two now) no longer recognize the TOD files from my JVC camcorder. The best available fix for that is iVerio for Leopard ($75), which is quite unstable on Snow Leopard. I recognize that Adobe is being greedy, JVC is being stupid and HP is living in some Windows-centric dreamworld, but this is ridiculous. I love Apple, but they can't just point fingers at everybody else this time. In my experience, Snow Leopard is a disaster.

    Thanks, Barry. Sorry for the rant, but this has been a highly frustrating upgrade -- a first with Apple for me. Part of my frustration is that I have already uninstalled and reinstalled the drivers in several times, in several different ways, but the problem persists. I'm not trying to be argumentative or accusatory about this, and your larger point is well taken. But several of the most important things I use my computer for have been disabled by this upgrade, and I had no idea that was coming. The only issue I'm looking for help with right now is printing. My printer is supposed to be supported, but I can't make it work in several days of trying. I'm just looking for a workaround. (Rant alert: Why does HP make fifty or more different printers that all do basically same thing but require unique drivers?) I guess maybe I have to repost my question under an assumed name when I calm down. But thanks for responding, Barry.

  • Mac OS 10.4 Install Stops After First Disc

    I'm trying to do a fresh install of mac os 10.4 on my mac mini g4. I restarted the computer with Disc 1 and booted up while holding C. I went under options and chose to do a fresh install. After it checked disc 1 the install began. After it finished with disc 1, it restarted and then it gave me the message, "Please insert the 'Mac OS X Install Disc 2' disc to continue installation. (You have chosen to install software that requires this disc)."
    This is where the problem is, I insert Disc 2 and after about 10 seconds, it spits it back out. Nothing on the screen changes.
    I've tried restarting it, inserting disc 1 again, restarting the installation process, and restarting while holding C with disc 2 in. None have gotten me past that message.
    The discs I am using are the ones that came with the Mac Mini (two gray discs).
    Any help would be greatly appreciated!

    Hi there, That second Disk thing happens frequently, the best way around it is to do a Custom install, and eliminate enough Printer Drivers, Languages, Fonts, and Applications you don't need... then it may skip #2 altogether.
    http://support.apple.com/kb/HT1442
    So start over,

  • Background java thread stops after running the fx thread

    in my server thread i am accepting a file . so i used Platform.runLater() to display a scene that gets confirmation from user. But when it reach the scene it is not going back to the server thread.
    class server implements Runnable
    public void run()
    while(true)
    // accepts client
    Platform.runLater(new Runnable(){    //  after this fx its not goin to the while
    // display confirmation message
    // writing the file
    }

    Post a bit more code, calling Platform.runLater() will not cause this behaviour. In fact, it should immediately return and continue with the while. You can add print statements if you want to be sure what is happening.
    The only reason I could think of is if the while(true) is already on the FX application thread but that seems unlikely.

  • Shuffle stopping after first track

    When I put my iphone 3gs onto shuffle it plays one track and then returns to the home screen. Sometimes it thinks about playing a second track and you hear the slightest bit of it as the phone is returning to the home page but then its gone. Any help would be appreciated.

    well, to see what your query is producing in the CFDUMP, it
    should actually be :
    <cfdump var="#regionInfo#">
    This will show everything that is produced by the query and
    tell you if it is pulling the proper rows, just like in the DB.
    If it is generating the proper data in the CFDUMP at this
    point, you output to your users with the <CFOUTPUT
    query="regionInfo"> tag using the columns that you want to
    appear inside it.
    i.e.
    <CFOUTPUT query="regionInfo">
    #regionInfo.categoryID#, #regionInfo.regionID#<BR>
    </CFOUTPUT>
    ** I placed a BR tag at the end because if there is more than
    one row it will run together without any type of separation. Once
    you know the output is running properly, you can format the output
    as required.

  • Mail stopped after first iPhone sync

    I have a POP mail account that has been working great with Mail on my computer for over a year. I synced my iPhone and now, I can send and receive mail from that POP account on my iPhone, but on my computer in the Mail application, that mailbox is stagnant. It does not show any errors or act as if it is not communicating with the server.

    Regarding my update, I think that the mail going out may just be through the .mac server and not my POP mail account.
    Now my mail account will not work on my iPhone.
    And nobody seems to have any input on this. I am I the only one with this problem or just nobody care or is there just no resolution and nobody wants to waste their time?
    I

  • In ADDin JAVA upgrade , SAPJup is getting stopped after CHANGE_UME phase

    Hi ,
    We are upgrading our ECC 5.0 (ABAP + JAVA) to ERP2005 EHP4 SP level 5.
    In the Downtime phase of the upgrade, SAP Jup is automatically getting stopped after CHANGE_UME phase. I am not able to find out the error. Why it is getting stopped even i started it many times, it goes to the CHANGE_UME phase then automatically stopped.
    There is no error in CHANGE_UME_***_09.LOG file.
    <!LOGHEADER[START]/>
    <!HELP[Manual modification of the header may cause parsing problem!]/>
    <!LOGGINGVERSION[1.5.3.7185 - 630]/>
    <!NAME[J:\DV2ERPUpgrade\jupgrade\log\CHANGE_UME_***_01.LOG]/>
    <!PATTERN[CHANGE_UME_***_01.LOG]/>
    <!FORMATTER[com.sap.tc.logging.ListFormatter]/>
    <!ENCODING[UTF8]/>
    <!LOGHEADER[END]/>
    #1.5 #C000AC101E650000000003F25B6DF84B00048B183E648670#1278836149094#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.ucp.phases.AbstractPhaseType.initialize(AbstractPhaseType.java:758)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.ucp.phases.AbstractPhaseType.initialize(AbstractPhaseType.java:758)#Java###Phase has been started.#1#UPGRADE/UPGRADE/CHANGE_UME#
    #1.5 #C000AC101E650000000003F35B6DF84B00048B183E648670#1278836149094#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.ucp.phases.AbstractPhaseType.initialize(AbstractPhaseType.java:759)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.ucp.phases.AbstractPhaseType.initialize(AbstractPhaseType.java:759)#Java###Phase type is .#1#com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling#
    #1.5 #C000AC101E650000000003F45B6DF84B00048B183E648670#1278836149094#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#Java###  Parameter =#2#connect#standard#
    #1.5 #C000AC101E650000000003F55B6DF84B00048B183E648670#1278836149094#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#Java###  Parameter =#2#inputFile#UMEHandling.xml#
    #1.5 #C000AC101E650000000003F65B6DF84B00048B183E648670#1278836149094#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.ucp.phases.AbstractPhaseType.logParameters(AbstractPhaseType.java:412)#Java###  Parameter =#2#action#change#
    #1.5 #C000AC101E650000000003F75B6DF84B00048B183E64FF88#1278836149125#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.checkParameters(PhaseTypeUMEHandling.java:233)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.checkParameters(PhaseTypeUMEHandling.java:233)#Java###Checking phase parameters .#1#action, connect, inputFile#
    #1.5 #C000AC101E650000000003F85B6DF84B00048B183E64FF88#1278836149125#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.checkParameters(PhaseTypeUMEHandling.java:249)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.checkParameters(PhaseTypeUMEHandling.java:249)#Java###Phase parameters have been checked. All required phase parameters have been set.#1#3#
    #1.5 #C000AC101E650000000003F95B6DF84B00048B183E6578A0#1278836149156#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.execute(PhaseTypeUMEHandling.java:169)#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j2ee.phases.PhaseTypeUMEHandling.execute(PhaseTypeUMEHandling.java:169)#Java###Backing up UME settings from configuration manager.##
    #1.5 #C000AC101E650000000003FA5B6DF84B00048B183E6578A0#1278836149156#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j630.configutils.ConfigUtils630#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j630.configutils.ConfigUtils630#Java###Reading properties of service on node .#2#com.sap.security.core.ume.service#server#
    #1.5 #C000AC101E650000000003FB5B6DF84B00048B183E66E7D0#1278836149250#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j630.configutils.ConfigUtils630#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j630.configutils.ConfigUtils630#Java###Batch config tool has been initialized.##
    #1.5 #C000AC101E650000000004025B6DF84B00048B183EA4A868#1278836153297#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j630.configutils.ConfigUtils630#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j630.configutils.ConfigUtils630#Java###Reading properties of service on node .#2#com.sap.security.core.ume.service#ID8895050#
    #1.5 #C000AC101E650000000004035B6DF84B00048B183EA4A868#1278836153297#/System/Server/Upgrade/Phases/UPGRADE/UPGRADE/CHANGE_UME##com.sap.sdt.j630.configutils.ConfigUtils630#######Thread[main,5,main]##0#0#Info#1#com.sap.sdt.j630.configutils.ConfigUtils630#Java###Batch config tool has been initialized.##
    My ABAP upgrade is ruuning fine in the downtime phase.
    Please suggest me ASAP.
    Thanks,
    Chetan

    Hello - we are facing the exact same problem while uprading a dual stack system.  How did you fix the problem?  We also opened up a ticket to SAP and we are waiting to hear back from them.  Any information you can share will be greatly appreciated.  
    Thank you.
    Nameeta

  • Installation of Flash stops after 30% complete, plugins and java are enabled in the browser and all browsers are closed.

    installation of Flash stops after 30% complete, plugins and java are enabled in the browser and all browsers are closed.

    Hi,
    I'm assuming you're machine is OS X (please include this in the future, avoids assumptions).  Are you using anti-virus software, if so, if you stop/exit the anti-virus software, does the installation proceed?
    If not, or if the installation still does not proceed after stopping the anti-virus software, please try the offline installer, posted at the bottom of the Installation problems | Flash Player | Macpage, in the 'Still having problems' section.
    Maria

Maybe you are looking for

  • Budget in Training and Events

    Hello, I'm trying to configure the budget in training module. I will not have integration with Billing and Materials Management so I only want to create a Budget and have always the budget comparison, this means to compare the budgets created for eac

  • Blue Screen of Death in Windows

    Hello, I am getting the Blue Screen of Death about once a every few days. My iMac does not do this. Please help. My HD is defragmented. I have Windows XP Home. Thanks!

  • I recently downloaded and installed Firefox 3.6.8 and all of my bookmarks disappeared. How do I get them back?

    I recently installed Firefox 3.6.8 on my computer and had to reboot. When I did the reboot, all of my bookmarks had disappeared, all 30-40 of them. How can I get them back. Some are very difficult to get and almost impossible to find again. I am usin

  • Payment difference

    Dear Guru's I need a help from you. I am trying to do the payment differnce, but it is now happening automatically when I am doing F-53. It is asking me to give the GL Account mannually rather that taking the payment difference to a seperate GL Accou

  • Table & Index Compression on 11g

    Hi, We are planning to upgrade oracle ( RAC ) from 10.2.0.4  to 11.2 and planning to turn on table and index compression. I would like to learn the pros & cons of turning compression on in a 6TB database. Any performance issues after table/index comp