Regex: searches for first letter in word return all letters

I want to init-cap the words in a sentence, and I use the pattern "\\b[a-z]" to search for the first letter of each word. However, it actually matches all the letters, so that the entire sentence is capitalized. If I reverse the pattern to look for the last letter of each word, "[a-z]\\b", then only the last letter is capitalized as expected.
Is this a bug or a misunderstanding of regular expressions on my part?
Here's my code:
String s = "this is a test";
Pattern p = Pattern.compile("\\b[a-z]");
Matcher m = p.matcher(s);
StringBuffer sb = new StringBuffer();
boolean result = m.find();
while(result) {
m.appendReplacement(sb, m.group().toUpperCase());
result = m.find();
m.appendTail(sb);
System.out.println(sb.toString());

It capitalizes only the first letter of words for me. Try getting the latest version of the JDK.

Similar Messages

  • Country list dropdown search by first letter doesn't work for some countries in the list

    Hi,
    We have this issue with the country list search in Travel Request with the drop down list when user is trying to choose the country by entering the first letter say C for Canada (finds Canada in the list) it works for the countries from A to O  and  doesn't work from P to Z.
    It is NW7.31 portal
    What seems to be the problem ?

    Hi Denis
    Get them to take a look at this wiki page:
    http://wiki.scn.sap.com/wiki/x/2oQCFQ
    It lists the latest notes for your basis version and the notes are usually cumulative which means if you apply the latest notes, it will bring in the pre-requisites and earlier notes too.
    Hope it helps you Denis.
    Sally

  • Dropdown country list search by first letter doesn't work for some countries in the list

    Hi,
    We have this issue with the country list search in Travel Request with the drop down list when user is trying to choose the country by entering the first letter say C for Canada (finds Canada in the list) it works for the countries from A to O  and  doesn't work from P to Z.
    It is NW7.31 portal
    What seems to be the problem ?

    Hi Denis
    Get them to take a look at this wiki page:
    http://wiki.scn.sap.com/wiki/x/2oQCFQ
    It lists the latest notes for your basis version and the notes are usually cumulative which means if you apply the latest notes, it will bring in the pre-requisites and earlier notes too.
    Hope it helps you Denis.
    Sally

  • STARTS SEARCH ON FIRST LETTER

    When I try to do a file search using Spotlight or using the window file search feature, the system does not give me a chance to type the whole word and starts searching on the first letter. It will not allow me to stop the search until it is completed or I have to quit the application. Is there anyway to type in a whole word or file name before searching? My only alternative has been to keep the MAC OS 9 Find File application on my dock which gives me exactly what I want after MAC OS 9 boots up. Find File gives me a list of files to scroll through instead of trying to figure out if the file is a document, movie, music, pdf, attachment, and then having to search these subheadings for the file. Is there a simple find file application for Tiger where I can type in a word and get a list of file names instead of all of these subheadings?

    Hi Marcia,
    You might want to try a little app called Laserlight:
    http://mysite.verizon.net/oneleftfoot/laserlight/
    It's a simple little program that presents a search box that won't start searching until you hit return. It then passes the search string to spotlight and the search carries on as normal.
    It's totally free, so give it a try and see how you get on with it.
    All the best,
    Deegan
    TiBook G4 15" 1ghz   Mac OS X (10.4.3)  

  • Help to search for a string value and return the index in the arraylist

    Hello,
    I just start java programming for the last three weeks and I cannot find a solution for this problem. I have the following List with string and integer value as shown below:
    List<Empl> list= new ArrayList<Empl>();
         list.add(new Empl(1,"Jim", "Balu",88);
         list.add(new Empl(3,"Bob", "Howards",2);
         list.add(new Empl(2,"Chris", "Hup",8);
    I have no problem of sorting this arraylist either by firstname or lastname. However, I cannot think of a way to search for a firstname or lastname and returing the whole row. I do not want to use index since I am asking user to enter the name to search. Here is my code to search for an empl based on index.
    System.out.print("Please enter index to search or (q)uit: ");
              String ans = sc.next();
              System.out.println();
              int ians = Integer(ans);
              if (ans.equalsIgnoreCase("q"))
                        choice = "n";
              else
              System.out.println("index " + list.get(ians)); //this will print out the whole row based on the index
    Since the user will never seen the contents of the arraylist, is there a way that I can search by string last/first name and will get the index location in int if the result is met?
    Please advice and thank you.
    Bob.

    user11191663 wrote:
    Since the user will never seen the contents of the arraylist, is there a way that I can search by string last/first name and will get the index location in int if the result is met?Another possibility is to set up an ArrayList for each thing you want to search on and then every time you add an employee, add the piece of data you want as well, viz:
    Empl e = new Empl(1,"Jim", "Balu",88);
    list.add(e);
    firstNames.add(e.firstName());As long as you always add them in the same order, the indexes will match, so you could do something like
    ians = firstNames.indexOf(nameToFind);to return the index of the name, if it's there (if not, it will return -1).
    I wouldn't recommend this as standard practise, but it should be OK for the level you're at.
    NOTE: indexOf() returns the index of the FIRST matching item. You may want to think about what you want to do if there are more than 1.
    Winston

  • How to Search for text in a word document and replace it

    Hey All ,
    I am able to open up a word document present locally using OLE2 Automation. Now i need to search for a text in that document
    and replace it with another text. How do i achieve this?
    And another issue is when i search for the particular pattern i need to store the pattern that comes after the pattern as i need it for further use before i replace it.
    Thanks And Warm Regards,
    Nischal

    Hey Chen,
    Well before i do the search and edit , I am actually opening a .mts file in word which is happening successfully.
    The issue that i am facing now is I am unable to save it as .doc file through the 'SaveAs' method.
    Here is my code. Can u please tell me what i need to do in order to correct this.
    After i do this conversion i intend to pass the data from the .doc file to an internal table and then do the required change.
    But First i need to save it to .doc type.
    REPORT  MAIN_PROGRAM_2.
    INCLUDE OLE2INCL.
    *Declaration Of OLE2_Object Variables.
    DATA: WORD            TYPE OLE2_OBJECT,
          DOCUMENTS       TYPE OLE2_OBJECT,
          ACT_DOCUMENTS   TYPE OLE2_OBJECT.
    *Declaration of variables
    PARAMETERS PATH       TYPE string.
    DATA:Relative_Path    TYPE string,
         Relative_Path_Save    TYPE string.
    *Declaration of an internal table
    CONCATENATE PATH '\Script.mts' INTO RELATIVE_PATH.
    *Object Creation in order for us to open word
    CREATE OBJECT WORD 'WORD.APPLICATION'.
    PERFORM ERROR_HANDLE.
    *Set visibility property of MS word.
    SET property of WORD 'VISIBLE' = 1.
    *Open A document
    CALL METHOD OF WORD 'Documents' = DOCUMENTS.
    PERFORM ERROR_HANDLE.
    *CALL METHOD OF DOCUMENTS 'ADD' = ACT_DOCUMENTS.
    CALL METHOD OF DOCUMENTS 'OPEN' EXPORTING #1 = RELATIVE_PATH.
    PERFORM ERROR_HANDLE.
    *GET PROPERTY OF WORD 'ActiveDocument' = ACT_DOCUMENTS.
    *PERFORM ERROR_HANDLE.
    **To save the script.mts to script .doc file in order to put it into an internal table
    CONCATENATE PATH '\Script.doc' INTO RELATIVE_PATH_SAVE.
    CALL METHOD OF WORD 'SaveAs' EXPORTING #1 = RELATIVE_PATH_SAVE.
    PERFORM ERROR_HANDLE.
    FREE OBJECT WORD.
    The Save part of the code is giving me an OLE error = 2
    Thanks And Kind Regards,
    Nischal
    Edited by: Nischal HP on Apr 28, 2011 1:53 PM

  • Converting first letter of word to uppercase

    Hi,
    Is there any function module to convert the first letter of the word to uppercase ?
    --bala

    Hi
    This will convert only the first word. If i have to do for all the words, like.,
    twinkle twinkle little star
    to
    Twinkle Twinkle Little Star.
    --bala

  • LDAP Addressbook search - match first letter only

    According to the SPA500 Admin Guide, a LDAP query will search on every letter:
    "This searches for the text string anywhere in the beginning, middle, or at the end of a name."
    Would it be possible to search only on the first letter of a name?
    Erik

    Eric, I don't know if you ever solved this request.
    In the search syntax you will see the "$VALUE" criteria bounded by two "*". These serve as wildcard matches. If you simply delete the first "*" before $VALUE your match will start at the beginning. Likewise if you remove the second "*" instead the search will try to match at the end. If you remove both it will look for an exact match.
    John

  • Unable to search for first record using the Preview tree

    Post Author: TheBig1980s
    CA Forum: General
    Hello:
    Users are unable to search for the first record in the Preview tab's tree.  The reason for this is because the first record is within the first page header of the report.  My guess is that, by design, Crystal takes the end user to whatever the first instance of the record iseven if that first record is in a page header.  That's not "good".  I want the user to be taken to the first record within the details of the reportnot within the page header.
    I have suppressed the page header to not print on the first record by using OnFirstRecord.  But, I still get the same issue where end users cannot select the first record in the tree without being taken to the page header.  Very strange.
    Can anybody think of any other ideas?
    Thanks!
    TheBig1980s

    Thank you Dave Merchant and try67 for your responses. As per my previous post, I contacted the company re the catalogue and they have responded favourably. I'll include their response because it gives the reason for the search failure as document compression which you might find interesting. I'll await their new catalogue and see if they have fixed the problem.
    Company response:
    Thank you very much for your input.  And yes, you are correct, the compression we used for the current catalogue's PDF format does strip out text included in the catalogue.  We used the compression settings we did with the intention of minimising download time, however I take your point about including text for search purposes (which I also utilise when I'm scanning through PDFs).
    We will actually be posting out our new catalogue next week and we'll release the new PDF version on the website at the same time.  I've asked our graphic designer to ensure that the PDF we use for the new catalogue includes searchable text.

  • Taking just first letter of words

    How can i take just letter of words?
    For example:
    words: marty fly result : MF

    A slightly different solution can take advantage of the initcap function.
    example
    with testdata as (select 'marty fly result' txt from dual
            union all select 'How can i take just letter of words?' from dual
    select txt,
           translate(initcap(txt),'$'||lower(txt),'$') res
    from testdata;
    TXT                         RESULT
    marty fly result               MFR
    How can i take just letter of words?     HCITJLOWJust noticed that Frank already posted a very similiar solution.
    Edited by: Sven W. on Jan 7, 2011 2:01 PM

  • Safari won't let me use first letter in word in dropdown list

    When I'm in a page with a dropdown list, Safari won't letter me type the first letter key to narrow down my selection. If, for example, I'd like to find Denmark, I can normally click on the D key. I know Safari for Mac allows that.

    I can't do it either - possibly an as-of-yet unimplimented feature in this beta release.

  • No capital A when first letter of word.

    I Cant get the shift A to give me a letter when A is the first letter of a sentence. I have to use the cap lock key, and this is only on one of my accounts, any ideas?

    Hi, as it is only on 1 of your accounts I would:-
    (1) Repair Permissions (2) Go the SMC reset Route
    I Googled your Issue & some people said that they had not installed the latest updates...L

  • On iMac maverick using numbers how do I search for an address without scrolling through all. Chris

    On iMac with maverick using numbers spreadsheet, how do I search for an address without scrolling through the lot.

    Better to post your topic in the dedicated Numbers community >  Numbers for Mac: iWork: Apple Support Communities

  • How can I search for document content, specific words, in my scanned (and searchable) pdf files?

    When using spotloght to search my files for text within a scanned document, I may or may not find documents that were scanned by a scan program (ScanSnap) to a searchable PDF file on a firewire attached drive.
    Is there a specific manner that yeilds useable results 100% of the time?

    Spotlight should index PDF files (as well as Word and some other kinds of files) but it seems that PDFs are not created equal. I've seen and heard complaints that some scanner/OCR programs are saving files that aren't searchable and yours is one of them. Try opening one of the files in Preview and resaving it.

  • Binocular search for Cost Center is not returning any data

    Hi Gurus,
    When clicking on the SRM-Shooping Cart-Cost Assignment- Account Assignment Overview- Cost center Binocular search icon,  it is not returning any data.  However,  when drilling down in the Account Assignment Overview, you will see another Binocular search icon for Cost Center which is working fine.
    Any idea of how you troubleshoot it.
    Thanks in advace for your help.
    HA

    Not sure about the cost assignment drill down, but after we applied SP13 to SRM server 550 the binoculars for cost center stopped working. the following note corrected this.
    Note 1259735 - Search help of generic account does not work
    If it has never worked, then probably need to setup a RFC dialog user for the F4 search help, Multiple threads on here around the dialog user for F4 with details on configuration and use.
    JF

Maybe you are looking for