Cannot find a specific pattern in text

Hi,
I want my code to search for a pattern in a line and then if it is there do something. The pattern may be followed by a comma, or tabs or white spaces or can have spaces before it. I am trying as follows:
public static void testWordBoundary(){
          String text = "     /m/075g     blah blah     ";
          String pattern = "/m/075g";
          Pattern search = Pattern.compile("\\b"+pattern+"\\b");
          Matcher m = search.matcher(text);
         if(m.find()){
              System.out.println("Found");
         else{
              System.out.println("Expression not found!");
}How can I achieve this? This above code does not work. Also, I cannot use "contains" method of string class as it says that the pattern exists if my text contains: "/m/075gzbpblahblah" as my pattern exists as a substring in the text.
What can be a solution to this?
Thanks

Hi
@Kamal: Thanks for your reply but your solution will not work if second text in my example is provided. Let me know..
@Sabre. Thanks for the reply. Actually anything can before and after the pattern, not just a white space or new line. The pattern can be at the end of the string as well: meaning there can be a carriage return after that as well. Sorry for the confusion. Probably that text was a bad example.
Now I am trying with pattern.compile("\\B"+pattern+"\\b") which seems to work fine. Is there some issues with this new technique or is there any more sophisticated means? Will I land up in trouble with this new approach? How can this be rectified?

Similar Messages

  • I cannot find one specific email

    I have tried multiple times with different email searches, but generally, I am on the street using wifi trying to locate the one email that I know I saw somewhere on the computer earlier. It's either archived in a folder aka "label" if gmail or filed if using Outlook. However, no matter how many correct search parameters (sender, subject), the ipod mail search turns up nada. Whenever I go onto my email account using a computer, I search using the same keyword for less than a second, and it appears. What is the best way to find specific emails in searches when I need them?!

    Try:
    http://email.about.com/od/iphonemailtips/qt/Search_Mail_in_iPhone_Mail.htm
    Are you sure that email message is on the iPod?

  • I obtain a 'General Failure....cannot find a specif file". How do I eliminate?

    When I open a web site from Outlook, I get the above error message. The web site does open however after a delay. I understand this is common with Firefox.
    how do I resolve.

    Is it in the resenltly added playlist? Did you use Search to look for the Artist, Album or track name. It may not be displayed because some track info is missing.
    Some people have reported that when importing CDs they do not show up. I have never experienced this behaviour but there are three "Fixes" out there
    1) If you are an iTunes Match user Store > Update iTunes Match
    2) Log out of itunes and then login again
    3) Download the free single of the week

  • Find character pattern in text

    Hi All !
    Have anyone you programmed a vi the finds a specific pattern in a text file
    and the place where it ends ?
    Regards
    Anders björk

    Hi Anders
    Have you looked in the string palette?
    There is a function called 'Match Pattern', I think it will meet your needs perfectly.
    Tim
    "Anders Björk" wrote:
    > Hi All !
    >
    > Have anyone you programmed a vi the finds a specific pattern in a text file
    > and the place where it ends ?
    >
    > Regards
    > Anders björk

  • Photoshop not updating on creative cloud, and cannot find textures

    hey I need help im trying to update photoshop on creative cloud on my alienware computer windows 8
    it will not update it keeps saying retry or contact support I have tried a few times but it will not update
    support cannot help with my enquire
    also I cannot find textures and patterns in photoshop

    What version of Photoshop and which update is failing? Update can be downloaded and installed manually some times. Whet error messages are you getting.
    Photoshop: Basic Troubleshooting steps to fix most issues
    Adobe - Photoshop : For Windows
    All Adobe CC 2014 Updates: The Direct Download Links for Windows | ProDesignTools
    All the Adobe CC Updates: The Direct Download Links for Windows | ProDesignTools

  • Download Camera Raw 8.3 update for my Photoshop CS6-How do I do it?  I cannot find this option anywhere on the download sights for Adobe PS.  Please help with specific instructions.  Thanks

    I cannot find anywhere on the Adobe sights the specific page where I can download Photoshop CS6 Camera Raw Update to 8.4 or 8.4 to support Lightroom 5 and my new Sony a7r camera.  Please help.  I am a tech novice.  Thanks.

    Rodger,
    Thank you for your gracious welcome . . .
    and thank you for your swift response . . .
    and thank you for your information (and encouragement!).
    Yes, I read that too, but searched in vain for the specifity of, say, your direction:
    "Go ahead and update to 8.0.2, as it contains the 8.0.1 update."
    So I shall!
    Again, many thanks.

  • I have downloaded a pattern and cannot find the download on my ipad

    I Have downloaded some knitting patterns from Etsy and don't know where they are stored.i cannot find them on the iPad.???

    The pdf files should still be in your email. Open the email again. Tap and hold down on the pdf icon and a window will pop up with apps that you can open the pdf files in. If you have the iBooks app, save the files to there. You can open and print them from iBooks. If the PDFs files are already open in the email, tap anywhere on the open pdf and you will see the action icon in the upper right corner. Tap that icon and you will get the same Open In window and you can choose iBooks from there. When you go back to the mail app, if you have to close the pdf file, tap on it again and you will see Done in the upper left corner. Tap that to close the file.

  • I'm trying to run an action to apply a specific swatch to an image. I'm getting an error that says "Cannot find swatch"

    The below screen shot displays the issue I'm having. I'm attempting to put together an automated batch to add a specific swatch to files. I'm getting an error "Cannot find swatch" when we attempt to do this. The swatch already exists on the computer and is saved to the library. I'm using Illustrator CS5.1
    My google-fu is failing me, does anyone have any suggestions? It would me much appreciated.

    Check and make sure the swatch is in the swatches panel and the name is exactly the same and what the action is looking for.

  • Error: cannot find symbol method Text

    Hi
    I want to make an index for txt files by using Lucene, it got an error: cannot find symbol method Text. what is it about? Does it mean the Text is not in Field?
    thank you v much
    pls look into my code:
    package TestLucene;
    import java.io.File;
    import java.io.FileReader;
    import java.io.Reader;
    import java.util.Date;
    import org.apache.lucene.analysis.Analyzer;
    import org.apache.lucene.analysis.standard.StandardAnalyzer;
    import org.apache.lucene.document.Document;
    import org.apache.lucene.document.Field;
    import org.apache.lucene.index.IndexWriter;
    import org.apache.lucene.document.Fieldable;
    import java.io.Serializable;
    * This class demonstrate the process of creating index with Lucene
    * for text files
    public class Lucene {
         public static void main(String[] args) throws Exception{
              //indexDir is the directory that hosts Lucene's index files
            File   indexDir = new File("D:\\luceneIndex");
            //dataDir is the directory that hosts the text files that to be indexed
            File   dataDir  = new File("D:\\luceneData");
            Analyzer luceneAnalyzer = new StandardAnalyzer();
            File[] dataFiles  = dataDir.listFiles();
            IndexWriter indexWriter = new IndexWriter(indexDir,luceneAnalyzer,true);
            long startTime = new Date().getTime();
            for(int i = 0; i < dataFiles.length; i++){
                 if(dataFiles.isFile() && dataFiles[i].getName().endsWith(".txt")){
              System.out.println("Indexing file " + dataFiles[i].getCanonicalPath());
              Document document = new Document();
              Reader txtReader = new FileReader(dataFiles[i]);
              document.add(Field.Text("path",dataFiles[i].getCanonicalPath()));
              document.add(Field.Text("contents",txtReader));
              indexWriter.addDocument(document);
    indexWriter.optimize();
    indexWriter.close();
    long endTime = new Date().getTime();
    System.out.println("It takes " + (endTime - startTime)
    + " milliseconds to create index for the files in directory "
              + dataDir.getPath());

    Hal-.- wrote:
    I downloaded Lucene from its homepage, I have tried Lucene 2.3.0 and Lucene 2.2.0, but same errors occurs which is cannot find symbol method Text.
    I checked class Field under Lucene, it doesn't have Text function. Well there you go. You can't call methods that don't exist.
    What should I do to add two Fields "path" & "contents" into Document?It seems very likely that the object that represents an indexed document, has some way to express the concepts of "path" and "contents". You should probably just read the docs some more.
    But other than that I have no idea. Ask on a Lucene forum.

  • HT204389 I cannot get siri to recognize my contacts?  Whenever I say "text" one of my contacts it says cannot find...

    I cannot get Siri to recognize my contacts.  Other functions of Siri work eg. what is the weather, how do I get home, where am I.
    Anytime I ask it to call, text, email any contact name it says it cannot find them in my contacts?

    If it says "Delivered" under it to begin with, then you're not sending it as an MMS, you're sending it as an iMessage. It's entirely possible the problem is on the receiving end.

  • How to find a specific text(string) in a list (100) programs

    Dear All,
    Wish tou a very happy new year 2009!!!
    please let me know how we can find a specific word(eg: "barrel") in a list of programs/reports/bdc/user exits/field exits/function modules.
    Thanks in advance.
    Kumar.

    hi kumar,
    open EWK1 transaction and search for the word or string according to your requirement.
    Cheers
    Gautham

  • HP OFFICEJET PRO 8500 - Will not install on wintows 8.1- says SYSTEM CANNOT FIND SPECIFIC FILE

    My HP Officejet 8500 will not install on windows 8.1.  The error message says:
    The system will not find the specific file

    Hi,
    Follow the steps below and check if that resolve the issue:
    1. Open Mcafee software, from the Virus and Spyware Protection section click on Schedule and run scans. Click on Real time scanning and then on Turn Off. select till I restart the PC and confirm by clicking the Turn Off button.
    Now try reinstalling the HP Software and check if the error no longer appear..
    If the issue persists continue follwoing the next steps below:
    2. Open the run dialog by clicking both the Windows key and the R key on your keyboard. Type %windir% and click on OK.
    3. Type hpoins*.dat into the top search bar, if there are any results rename the extention into old instead of dat. (e.g. hpoins1.old)
    4. Type hpwins*.dat into the top search bar, if there are any results rename the extention into old instead of dat. (e.g. hpwins1.old)
    5. Launch the Run dialog by clicking both the Windows key and the R key on your keyboard. Type MSIEXEC /UNREGISTER into the Run dialog and click on OK.
    6. Launch the Run dialog by clicking both the Windows key and the R key on your keyboard. Type MSIEXEC /REGSERVER into the Run dialog and click on OK.
    7. Run the installation file and check for any difference.
    Regards,
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Error occurred in deployment step 'Recycle IIS Application Pool': Could not load file or assembly 'Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specif

    Hi All,
    I am using Virtual box to connect to Sharepoint 2013 VPC. Due to an unexpected sutdown of my machine the VPC got some issue. Now I restored it using my bak up file. But after this when I deploy my sharepoint 2013 farm solution Iam getting the following error.
    Error occurred in deployment step 'Recycle IIS Application Pool': Could not load file or assembly 'Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified..
    Editing the web.config and adding dependentAssembly didnt worked for me.
    What could be the issue? Any suggestions ?
    Thanks in advance...
    Regards
    Nimisha
    [email protected]

    Hi,
    Please try to do as follows:
    1. Check your farm solution whether reference the Microsoft.SharePoint.dll. Or try to add the Microsoft.SharePoint.dll into the bin folder.
    2. Execute the iisreset command.
    3. Create a new farm solution and check whether the issue still occurs or not.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Cannot find symbol error -- array fill from text file

    When I compile my program I receive a cannot find symbol error for the variable ayears. I thought this snippet would fill the array ayears that could be accessed later in the program but I am getting the error message from my buildGUI() class. What could I have done wrong?
    (my file options.txt contains data separated by a comma and a space)
    public void getOption(){
         InputStream istream;
         File options = new File("options.txt");
         istream = new FileInputStream(options);
         try {
                               StringBuffer sbuff = new StringBuffer();
                               BufferedReader inbuff = new
    BufferedReader(new FileReader(options));
                               String line = "";
                               while((line = inbuff.readLine()) != null) {
                               System.out.println(line); 
              sbuff.append(line);
                               inbuff.close();
                              String fileData = sbuff.toString();
              String[] splitData = fileData.split(", ");
              String[] ayears = new String[splitData.length];
         catch(Exception e){
         JOptionPane.showMessageDialog(null,
         "Could not find specified file", "Error Message",
         JOptionPane.ERROR_MESSAGE);
    }

    Okay -- that helped. I've avoided that error -- now on to the next one, why won't my array fill? It's going to be a long night.
    Thanks for the help.

  • I Need to Reinstall iWork (specifically Pages) but cannot find Install Disc.

    I had the most recent version of Pages, but bought it on disc before the App Store came around.  Now I need to reinstall and I cannot find the original disc. The App Store does not recognize that I own it.
    Do I have any options to reinstall or am I doomed to purchase it all over again through the App Store?

    If you can't find the disk or restore Pages from backup, you'll need to buy it from the Mac App Store.
    (72085)

Maybe you are looking for