Different results using Matcher.replaceAll on a literal depending on the Pattern compiled

I would have expected that the results for all the following scenarios would have been the same:
public class PatternMatcher {
    public static void main(String[] args) {
        Pattern p;
        Matcher m;
        // duplicates
        p = Pattern.compile("(.*)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // single
        p = Pattern.compile("(.+)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // wtf
        p = Pattern.compile("(.*?)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // duplicates
        p = Pattern.compile("(.*+)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // single
        p = Pattern.compile("^(.*)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // duplicates
        p = Pattern.compile("(.*)$");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // single
        p = Pattern.compile("^(.*)$");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
        // single
        p = Pattern.compile("(.(.*).)");
        m = p.matcher("abc");
        if (m.matches()) System.out.println(p + " : " + m.replaceAll("xyz"));
But the results vary depending on the pattern compiled:
(.*) : xyzxyz
(.+) : xyz
(.*?) : xyzaxyzbxyzcxyz
(.*+) : xyzxyz
^(.*) : xyz
(.*)$ : xyzxyz
^(.*)$ : xyz
(.(.*).) : xyz
Since all of the patterns have an all-encompassing capture group, but the replacement string does not have any group references, I was expecting that in every case the replacement string would simply be returned unchanged (so just "xyz").
Have I uncovered a bug in the core library?  or am I misunderstanding how this should be working?

jwenting wrote:
And such is the case here.
"You're doing it wrong, but I'm not going to tell you what it is you're doing wrong nah nah nah"
That's the good thing about long lasting platforms such as Java - APIs become mature because they've been tested and re-tested by thousands of people for more than a decade. And thus when you go to use them and have to think "wtf", you can be almost certain you simply don't understand and meanies in forums can say so without having any ammunition to back up that accusation.

Similar Messages

  • Two very different results using the same settings (H.264 / Quicktime Pro)

    I’m a bit confused, I have used Quicktime Pro (v7.1) to encode DV into H.264 for iPod and this particular video is 18 minutes long and came out looking very good with the following settings;
    VIDEO: H.264 at 200kbps, Baseline Profile, 25fps, Auto Key Frames, 320x240 or 640x480, Multipass Best quality encoding.
    AUDIO: AAC Audio at 96kbps, 24kHz sampling freq, Stereo.
    However here is the twist…
    When I use the same exact settings to encode just the 30 second opener (from the 18 minute video) the encoded opener looks bad and blocky!
    Why? Same settings would make you assume that you should get a same or similar result, or am I wrong?
    The reason I have tried encoding this 30 second opener is that I am trying to work out which settings work best on the iPod (another issue) and I don’t want to spend hours test encoding the full 18 minute video, as you know H.264 is SLOW to encode!
    So can anyone help in regard to two very different results using the same settings?
    Regards,
    J
    PC   Windows XP  

    Alvin,
    Is it a commercially-released or home-burned CD?
    If it's commercially-released, try "encouraging" the recalcitrant computer by using the iTunes Advanced menu > Get CD Track Names command when it shows Audio CD.
    If it's home-burned, you will find that only the computer that actually burned the disc will know what's on it. The information won't be transferred to another computer.
    Let us know which, if either, of these situations applies to you.

  • Two different results using one query

    Hi Friends
    Oracle version that I am using is : Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    I have a scenario where one account can be related to two customers. Hence, in table have many rows for one account. Here’s the sample data:
    Account_ID | product_code | cust_id | relationship_code | entity_code
    1111 | ABC | 1234 | SOL | CUST
    1111 | ABC | 2222 | ZZZ | LINK
    1111 | ABC | 4455 | ABC | LINK
    2222 | ABC | 7890 | SOL | CUST
    2222 | ABC | 5678 | ZZZ | LINK
    3333 | JFK | 5878 | TST | CUST
    3333 | JFK | 3254 | PRI | CUST
    3333 | JFK | 3299 | PRI | CUST
    4444 | JFK | 2535 | SOL | CUST
    4444 | JFK | 4565 | SOL | CUST
    5555 | DEF | 6666 | PRI | CUST
    5555 | DEF | 6667 | TST | CUST
    5555 | DEF | 9667 | TST | CUSTIn this scenario, I need two outputs differently:
    Output 1: When an account has relationship_code = ‘SOL’ then take the least cust_id
    1111 | ABC | 1234 | SOL | CUST
    2222 | ABC | 5678 | ZZZ | LINK
    4444 | JFK | 2535 | SOL | CUST Output 2: else take the highest cust_id
    3333 | JFK | 5878 | TST | CUST
    5555 | DEF | 9667 | TST | CUSTHow can I get this result using one query?

    Not sure what you mean. Works OK:
    SQL> with t as (
      2             select 1111 account_ID,'ABC' product_code,1234 cust_id,'SOL' relationship_code,'CUST' entity_code from dual union all
      3             select 1111,'ABC',2222,'ZZZ','LINK' from dual union all
      4             select 1111,'ABC',4455,'ABC','LINK' from dual union all
      5             select 2222,'ABC',7890,'SOL','CUST' from dual union all
      6             select 2222,'ABC',5678,'ZZZ','LINK' from dual union all
      7             select 3333,'JFK',5878,'TST','CUST' from dual union all
      8             select 3333,'JFK',3254,'PRI','CUST' from dual union all
      9             select 3333,'JFK',3299,'PRI','CUST' from dual union all
    10             select 4444,'JFK',2535,'SOL','CUST' from dual union all
    11             select 4444,'JFK',4565,'SOL','CUST' from dual union all
    12             select 5555,'DEF',6666,'PRI','CUST' from dual union all
    13             select 5555,'DEF',6667,'TST','CUST' from dual union all
    14             select 5555,'DEF',9667,'TST','CUST' from dual union all
    15             select 6666,'XYZ',8877,'SOL','CUST' from dual
    16            )
    17  select  account_ID,
    18          product_code,
    19          cust_id,
    20          relationship_code,
    21          entity_code
    22    from  (
    23           select  account_ID,
    24                   product_code,
    25                   cust_id,
    26                   relationship_code,
    27                   entity_code,
    28                   case max(case relationship_code when 'SOL' then 1 else 0 end) over(partition by account_ID)
    29                     when 1 then dense_rank() over(partition by account_ID order by cust_id)
    30                     else dense_rank() over(partition by account_ID order by cust_id desc)
    31                   end rnk
    32             from  t
    33          )
    34    where rnk = 1
    35  /
    ACCOUNT_ID PRO    CUST_ID REL ENTI
          1111 ABC       1234 SOL CUST
          2222 ABC       5678 ZZZ LINK
          3333 JFK       5878 TST CUST
          4444 JFK       2535 SOL CUST
          5555 DEF       9667 TST CUST
          6666 XYZ       8877 SOL CUST
    6 rows selected.
    SQL> SY.

  • Sandpit and Dev give Address search with different results using Web UI

    Using the Sandpit system I can perform a BP search on Street and enter the post code, but it still finds the right address. However, in our development sytsem it does not. The FM which performs the search is identical so I assume this would be down to some kind of address related config?. Can anyone enlighten me further as what could possible cause this?.
    Jason
    [RESOLVED]
    Edited by: Jason Stratham on Sep 8, 2009 11:35 AM

    Okay. So, I asked the admin to create a scope for the list, which they did following the steps outlined in Ben Tedders article, and then I followed the steps in the rest of the article setting up the web parts. When I ran a search, it returned the no results
    page. Not sure why, but I removed the scope from the Search Core Results web part, and the search returned usable data from the list.
    Here's my part ii question - - how do I customize the Search Core Results web part to display the data from the search in manner that makes more sense than from a list of nondescript layout of,
    Search Result
         Search Term ... dataField01 ... dataField02 ... dataField03 ... dataField04 ...
         author info
    url info
    to something a tad more informative, such as,
    You search for Search Term, with the following results:
         Search Result
              dataField01 label ... dataField01
              dataField02 label ... dataField02
              dataField03 label ... dataField03
              dataField04 label ... dataField04
    because nobody's really going to care who uploaded the list or want to link to the data pulled from the list in one of those columnar results tables.

  • Different results using View with union all in 11R1 compared to 10R2

    Hello,
    I have the following situation:
    In Oracle 10R2 I defined a view which looks like this
    create view test_view
    as
    select 'field1;field2;field3' field from dual
    union all
    select field
    from (
    select tfield1||';'||tfield2||';'||tfield3 field
    from table1
    order by tfield1,tfield2,tfield3
    The idea is, my first line contains a header information an then the data in the required sorting order.
    So, in 10R2, when I export the view with select field from test_view, I get the result as expected, which means, the header from the part with the dual was in the first line and after that, the data in the required sort order.
    Now, in 11.1.0.7, it is completely different, because the row of the dual is somewhere in my result set. But if I send the sql instead of the view, I get the expected result as in 10R2.
    I have no idea why this is the case now, because in 10R2 this was working permanently as expected. When I look at the execution plan, I see, that he starts parallelisation, which is ok, but the difference is, that in this parallelisation the select from dual is included and in 10R2 he first make the line from the dual and then the parallelisation with the data. It's not clear to me, that if I send the sql to the database I see the required result, but if i define the view as mentioned, and start a select field from view, I get now get the different sorting, because of the parallelisation, where the optimizer he changes his behavior comparing the both database versions. So my question ist, how can I change this behavior to get the same behavior as in release 10R2.
    Best regards
    Rainer

    Hello,
    thank you for your sample, I see your idea for my sorting purpose.
    I want to look at the following point:
    I create the table, as you described. The table has the degree and instances 1. Now I deefine the following view:
    create view view_test
    as
    select 'field1;field2;field3' field
    from dual
    union all
    select tfield1 || ';' || tfield2 || ';' || tfield3 field
    from (select * from table1 order by tfield1,tfield2).
    This is the way I used it in 10 R2.
    Now, the SQL select field from view_test delivers the expected result:
    field1;field2;field3
    a;b;c
    d;e;f
    So far so good. But now, I changed the degree of the table1 (alter table table1 parallel (degree 4 instances 1);).
    The result looks like that:
    a;b;c
    field1;field2;field3
    d;e;f
    So, the parallelisation of my object seems to be the reason for the, in my eyes, "wrong" sort order. In 10R2 I used this degree and instance values for my table and defined a view and it was working fine. Now, after our migration, I had this "trouble". For me it seems, that the optimizer made some changes, or mabe this is a bug, who knows ?
    I also tried, to change the nls_comp, and set the undocumented parameters as described in the Metalink note 7497640.8, but with no effect of my result set.
    Best regards
    Rainer

  • How to access mail if different users use same email - sent, trash, etc, are not the same in both user's thunderbird. How do I fix that?

    I have different users on my computer, me, spouse, etc. We share the same email. I have thunderbird loaded correctly in one account. In the other account it only grabs the inbox messages, not the sent messages. How do I get it so both thunderbirds work in both accounts on the same computer? Right now I need to switch user to view the sent emails that are sent from the other account.

    IMAP will sync messages, but if your sharing on a single computer you would probably be better off sharing the same profile. It is not as if you will both be using it at the same time. The information in this link should help with that.
    http://kb.mozillazine.org/Moving_your_profile_folder_-_Thunderbird

  • Why jpeg file exported from Aperture with 300 dpi's it opens with 72 dpi's on PS ( image size)? I've tried several combinations and all give different results. And I am confused on what is the best workflow for me.

    Ok.
    My workflow is
    RAW > Aperture Library > export jpeg high resolution 300 dpi's > one file on PS > edit > Save us jpeg. The I realised that files from PS were being save in a smaller size from the ones exported form Aperture. That is when I went o see <image size> on PS and files were with 72.
    Since ten I've trying different things
    1. Aperture > export as PSD > open on PS > edit > Save us jpeg = small file (around 15 MB)
    2. Aperture > export as jpeg high resolution 300 dpi's > open on PS > CHANGE dpi's to 300 on <image size> edit > Save us jpeg = big file (Huge, actually)
    What am I doing wrong? Would someone give me guidance and tell me what is the best workflow, considering I edit photos to deliver to my clients and I shall give them 300 dpi's.
    Thank you

    This is a known Aperture issue: Problem with Aperture 3.6 preset exports. | Apple Support Communities
    Benjamin

  • Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?

    Hello
    I'm currently developping an image processing algorithm using Labview 7.1 and the associated IMAQ Vision tools. After several tests, I found a weird result. Indeed, I put the labview algorithm - including the IMAQ VI on the library to get sure that I use all the time the same VI - on my memory stick and used it on two different computers. I tested the same picture (still in my memory stick) and had two very different results.
    After several hours trying to understand why, I found that there were a difference between the results given by both computers at the very begining of the algorithm. Indeed, I used a JPEG file.
    To open it, I first create an Image with IMAQ Create (U8). Then, I open it.
    Then in my first sub-VI, I use IMAQ Cast Image to be sure that the picture is a U8 grayscale picture.
    Right after that, I use the IMAQ Linear Averages. The results of this VI are different on the two computers.
    I tried several time on the same picture : one computer always give me the same result but the two computers give me a different result. So there is no random variable on the results.
    So my question is : Do IMAQ Cast Image or IMAQ Linear averages give different results when using different computers that are running under Windows XP ?
    My bet is on IMAQ Cast Image but I'm not quite sure and I do not undestand why. The labview and IMAQ are the same on both computers.
    The difference between the two computer are above :
    Computer 1 :
    Pentium(R) 4 CPU 3.20GHz with a RAM of 1Go. The processor is an Intel(R).
    The OS is windows XP Pro 2002
    Computer 2 :
    Pentium(R) 4 CPU 2.80GHz with a RAM of 512Mo. The processor is an Intel(R).
    The OS is windows XP Pro 2002.
    If anybody can help me on this problem, it would be really helpful.
    Regards
    Florence P.

    Hi,
    Indeed it's a strange behaviour, could you send me your VI and your JPEG file, (or another file that reproduces) so that I could check this inthere ?
    I'll then try to find out what's happening.
    Regards
    Richard Keromen
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Découvrez, en vidéo, les innovations technologiques réalisées en éco-conception

  • Exporting from PPro CC - Exporting using Match Sequence Settings issue with 24 bit audio

    I am having an issue exporting my sequence which contains final AIFF mix (24 bit 48 kHz) into a 'same-as-source' ProRes 422 file with 24 bit audio. I am specifically trying to export media with 'Match Sequence Settings' checked to create an identical output of what my sequence is. I wind up only creating a PR422 with 16 bit audio rather than 24 bit audio.
    My sequence contains ProRes 422 media and 24 bit AIFF final stereo mix (1 audio file) from our Sound department.
    My sequence is currently setup as "Custom" at 1920x1080, 23.976 fps, Square Pixels, Progressive, etc. Audio is 48 kHz (I don't see an option for choosing different bit rates in the 'Sequence Settings').
    Using 'Match Sequence Settings', my options to alter the audio are "greyed out" and unavailable. I'm not sure why 'Match Sequence Settings' doesn't recognize that I am cutting with 24 bit audio and, instead, only exports 16 bit audio.

    Always skip Match Sequence Settings and set up the export manually.

  • Why different types of peak detectors show different results?

    In my project i need to insert a peak detector but when i use different types of peak detectors they show different results. why is this so?

    I also find the thresholds used will give different results.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Integrating R/3 of two different landscape using XI ?

    Guys,
    Would like to integrate two R/3 Systems (4.6 C & 4.7) using SAP XI of two different networks which is in two different countries , for a synchronous scenario.
    Now , how to connect these two systems of different landscape using XI ?
    Cheers!

    HI,
    Please refer the guide for SLD configuration:
    SLD preparation very good:
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/flatFILETOFLATFILE&
    Working with System Landscape Directory (SLD) :
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/workingwithSystemLandscapeDirectory+%28SLD%29&
    Configuring SLD in Sneak Preview SAP NetWeaver '04 Sneak:
    /people/sugree.phatanapherom/blog/2005/08/14/configuring-sld-in-sneak-preview-sap-netweaver-04-sneak
    XI Software Logistics 1: SLD Preparation:
    /people/sap.india5/blog/2005/11/03/xi-software-logistics-1-sld-preparation
    Refer How to handle SLD guide for help:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/9e76e511-0d01-0010-5c9d-9f768d644808
    Also as said you need to use the party and the third party adapter for implementing the same over the differnet newtwork you can either go with the seeburger adapter.
    Wanna Party ?
    /people/shabarish.vijayakumar/blog/2006/09/13/wanna-party
    How to Set up an SAP XI Integration Directory Scenario with Party to Support EDI Partner Processing
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b0b355ae-0501-0010-3b83-8f2bb566fa47
    Do let me know if you need further information on the same.
    Thnx
    Chirag Gohil

  • We started using Match and now playlists are gone.   Can we get them back?

    My wife has spent a ton of time creating playlists but our music was all over - new computers and updated iPads and phones - we started using match.   Now the playlists are gone.   How can I get them back before I am gone.

    We have 3 ipads and 2 iphones.  She had the playlists on her ipad and iphone.  Since we started using match - they are gone now.  All the music is there.  Thank you for all of your help!

  • Cut vedio file into different frames using java

    Hi friends,
    I would like o know how we can cut the vedio file into different formate using JMF.
    Given an input media file, the object is to cut pieces from the file and generate an output file from that.
    i want to cut vedio from X time to Y time.
    If any one is work on this please help.

    Why "split" the file? Just write a packet with a DataOutputStream(GZipOutputStream()), send it, and then read it back with a DataInputStream(GZipInputStream()) ...
    1. The GZip*Streams take care of compression.
    2. The Data*Streams take of byte order and so on.
    3. Your DatagramPacket handles the transport.
    The hardest part is figuring out what buffer size works best for your network... there is no "right" answer to that.

  • How can I see different results for alternate hierarchy?

    I have an outline with an accounts dimension with the following members (amongst others):
    Total Expenses
    Exp1 +
    Exp2 +
    Exp3 +
    Exp31 + (child of Exp3)
    Exp32 + (child of Exp3)
    Exp33 + (child of Exp3)
    I also have another dimension, let's call it DIM, with the following primary and alternate hierarchies (shares upper levels with primary):
    Primary
    A
    A1 +
    A2 +
    A3 +
    B
    B1 +
    B2 +
    B3 +
    Alternate
    A + (shared member)
    B + (shared member)
    I want to be able to do the following:
    When I select something from the primary hieararchy, I want to see the original values in Exp31, Exp32 and Exp33. When I select a member from the alternate hierarchy, I want to see these 3 expenses zeroed out. Is this possible? I can't find a way to do this since the values for shared members are taken from primary members. Is there another way to do this?
    Thanks for your help.
    Bela

    I did think of creating an alternate hierarchy in the accounts dimension which excludes the expenses I do not want to include in the total, but I have 3 different categories of expenses I want to exclude depending on the members I'm viewing, so I'll have to create that many alternate hierarchies in accounts, each excluding a specific category of expenses.
    If you have a brainwave, please let me know!
    Bela

  • Different ways to return results using a stored proc to calling application

    Hi, Can someone please suggest me different ways of returning results( set of rows and columns) from a stored procedure to calling application.
    Currently I am using sys_refcursor to return results to front end. Stored proc is executed fast, but cursor access and retrieval of results has some overhead.
    So can you suggest the ways which will be faster than this approach.
    Thanks.

    Currently the procedure executes quickly but the results from the ref cursor are returned slowly, this is because the query is slow, for whatever reason.
    Collecting in all the rows in the stored procedure first before returning them will
    a) Make the stored procedure slower taking the same amount of time to execute as current query takes to complete.
    b) Use more memory.
    c) Put more stress on the network as all rows will be transferred at once instead of using the arraysize/fetchsize to to fetch the rows in smaller packets.

Maybe you are looking for

  • ITunes Crashed my computer!

    I am running a PC, and after installing the new version of iTunes I received a message saying installation complete, please restart your computer. After restarting my machine the screen was black and I can not even boot in safe mode. I don't know wha

  • Execute SQL Task Failing

    Hi there, I have this issue with my Execute SQL Task Failing. I am trying to execute a sp using an execute sql task. The execute statement is contained in a variable (exec [sp_name] par1, par2)  that I have declared at the package level. Now inside t

  • Adobe Audition line-in Recording Problems

    Hello, I've just started using windows 7, used to and still do use on other computers windows xp. I installed adobe audition 1.5 on the computer with windows 7. In xp you had to select line in, in the recording control to allow you to record if somet

  • N96 mass storage problem

    Hi my friends I have nokia n96 (RM-247) not branded and I experienced some problems after I install the new firmware 30.033. When I connect the phone in mass storage mode I am receiving the following message: Exception Processing Message c0000013 Par

  • Multimode transport for procurement

    Hi friends. I am a MM consultant. I need your opinion on the folowing issue. The client requirement is as follows. 1.     They procure coals and ore from mines and ports. For this the Transport of raw material is a significant process in their busine