Java methods won't recognize standard regex meta-characters

First of all, let me say that this is my first attempt at using Java regular expressions. However, I'm stumped as to why my code doesn't work
unless I use strictly text characters. Any use of standard regex meta-characters results in failure.
I'm re-writing a routine I've used for years that is written in Perl and works great. The program scans COBOL source code files looking for
instances of the COBOL syntax COPY followed by the name of a COBOL source code file. There will be at least one space between COPY and the
file name, but there may be more.
I've been using this pattern: \\.\*COPY\\s+FILENAME\\.\* Since the program loads every file in a directory and scans them one at a time, I
wanted to use the Pattern method compile to save time and then use the Matcher methods. The Java program compiles without errors but the match fails.
I abandoned the Pattern and Matcher, used the String method contains and reduced the input to just COPY\s+FILENAME but that didn't work either.
Finally I abandoned all regex meta-characters and passed the literal "COPY FILENAME" to the contains method. Success at last!
What gives? It's not like I'm doing anything particularly fancy.
Edited by: user735407 on Apr 13, 2012 9:47 AM
Edited by: user735407 on Apr 13, 2012 9:48 AM

This is the kind of stuff that makes me wonder sometimes whether I should just apply for a job an Mickey D's and give up this programming
s**t.
I copied the patern string from my Perl program, forgetting that I had specified the period (".") that should always follow the FILENAME
in the code as part of the pattern. I thought the backslash was necessary because the period was a meta-character.
I removed the backslashes in front of the periods and went back to the Pattern class compile method and the use of a Matcher to
match the pattern. Now it works!
Way back when I was just a fresh-faced young programmer, a developer with decades of experience was consoling me after I had spent
a whole day tracking down a compiler error and discovered a simple "fat finger" typing error. He told me that 25 years in the future, after
I had written thousands of programs in many languages, I would still be making exactly this type of mistake and that I had better accept
that fact or I would be fated to die an early death.
Thanks a million for saving me hours of futile code-bashing!!!!

Similar Messages

  • How to use sed on a literal string containing regex meta characters?

    I want to delete the lines from a file which match an arbitrary literal string.
    The string is contained in a variable, and may itself contain various regex meta characters such as [,],^,$,|, etc
    So, my problem is that sed wants to interpret these meta characters itself. For example:
    x='abc[xyz$'
    sed -i "/$x/d" file
    produces a sed error about the unmatched [, and no doubt it wants to interpret the $ too.
    (Of course, I could try and change the string $x so that every possible regex meta character was escaped with a \, but that seems immensely cumbersome. Also, can't see a way of using single or double quotes cleverly.)
    Sorry if I am being thick about this, but any ideas or alternative methods would be most welcome!

    frostschutz wrote:
    With sed, you have to escape meta characters indivudually. That's just how it works. Of course you could do the escaping using sed as well, by replacing all meta characters (including \ and /) with \character.
    If you want to match strings literally, use a different tool. Or do it in Bash.
    while read line
    do
    [ "$line" != "$x" ] && echo "$line"
    done < file
    In Perl/PCRE instead of escaping indivudually there is \Q...\E but sed does not understand that, and \Q\E does not solve all problems either, if there is a \E in the $x you have to escape it with \E\\E\Q or something like it.
    Thank you for your swift reply. Looks like sed can't be much of a friend in these circumstances!
    Probably will have to go with the Bash file handling method.
    Oh well ...

  • Acrobat 9 Standard won't recognize Canon Lide 200 Scanner

    My recently installed Acrobat 9 Standard won't recognize my  Canon Lide 200 scanner even though Adobe Photoshop CS2 does.  I don't know what the problem is and how to solve it.

    Adobe Acrobat Pro 9 was recently installed on new Vista 64bit computer and functions with all programs and even prints to my Dell 1600n printer, but when I try to scan from the printer, it causes this error message and shuts Acrobat down:
    "ADOBE ACROBAT HAS STOPED WORKING A Problem has caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."
    I have lived with this since I bought the computer a month ago. Still no solution from Adobe and no response to an email that I sent to adobe support.

  • Query object java method issue

    MyUsernameQuery['userNames'].indexOf('tomjones') will find
    the tomjones
    value in the query.
    BUT:
    MyUsernameQuery['id'].indexOf(99) won't find the numeric
    index value, even
    though it's in the record set.
    BUT WAIT, THERE'S MORE:
    If I manually build a query object with integer values and
    try a similar
    search for the numeric id value,it finds it!
    What's up with that?
    If it was a casting issue, why would it find it in the
    manually built object
    and NOT in the query object?
    I tried casting the integer as a string but no luck.
    I'm in over my head with these methods. Any help much
    appreciated.
    Cheers,
    Lossed
    __when the only tool you have is a hammer, everything looks
    like a nail __

    I should point out that the relative processing speeds are
    dependant upon
    the size of the recordset and position in that recordset of
    the value being
    searching for.
    "Lossed" <[email protected]> wrote in message
    news:eucai4$lhj$[email protected]..
    > It was indeed the casting.
    > I had to cast it as 'long'.
    > There are other ways to find if the value exists:
    > convert column array to list and listfindnocase(), Q of
    Q, loop over
    > query. I was trying to find the fastest. the underlying
    java indexOf()
    > method seems to leave the others in it's dust :).
    >
    > "cf_dev2" <[email protected]> wrote in
    message
    > news:euc51t$epr$[email protected]..
    >>> I'm in over my head with these methods
    >>
    >> Doesn't answer your question, but is indexOf()
    really the only way to get
    >> the
    >> job done? Just wondering if there is an easier way.
    >>
    >> The undocumented stuff is neat, but the java methods
    tend to be stricter
    >> about
    >> object type and case than many of the standard CF
    functions. Two things
    >> may
    >> appear the same but that doesn't mean they are the
    same to java. It can
    >> trip
    >> you up ;)
    >>
    >> That could be the problem with your number column.
    You didn't mention the
    >> column type but some numeric data types don't map to
    a java integer. For
    >> example a biginteger column might map to a java
    long. In which case
    >> searching
    >> for an integer wouldn't work. So it could still be a
    casting
    >> problem
    >>
    >>
    >
    >

  • ITunes won't recognize iPod Nano (1GB, 1st generation)

    I have been having problems Sync'ing my iPod nano with iTunes, however, the more I read help articles and follow the steps, the worse the problem gets. (I'm on a PC using Windows XP)
    I've gotten to the point where I updated my iPod software in Disk mode (up until then it was being recognized only in Disk mode), but when iTunes failed to recognize it when not in Disk mode I preceded to restore my iPod to factory settings, as instructed in the help articles.
    Now, up until then, I still had music in my iPod, and I was being able to charge it and listen to my music even though I couldn't sync the iPod anymore. After restoring, I not only lost my music (which I was aware of), but it STILL did not fix my problem. So I started to get annoyed.
    I then noticed that my iPod was being recognized by My Computer, just not by iTunes, so I began to perform the steps indicated in the following article:
    http://docs.info.apple.com/article.html?artnum=93716
    I restarted my iPod service - no luck
    I removed iTunes - no luck
    I emptied my Temp directory and restarted...
    That's when iTunes stopped recognizing my iPod altogether, not even in Disk mode. Not only that, but it seems to have affected the iPod itself, since it won't turn off or exit Disk mode anymore. So now I'm scared of going though with any more steps on whichever "help" articles and making the problem even worse than it already is (if that's possible).
    The only other information I can provide is that windows is still recognizing my iPod, no problem, and when I connect my iPod, iTunes actually launches... but DOESN'T recognize a thing. So I ran a diagnostics using iTunes and here's what I got (iPod diagnostics):
    Microsoft Windows XP Professional Service Pack 2 (Build 2600)
    INTEL_ D945GCL_
    iTunes 7.3.2.6
    iPodService 7.3.2.6 is currently running.
    iTunesHelper 7.3.2.6 is currently running.
    Current user is an administrator.
    The current local date and time is 2007-08-30 11:53:26.
    Connected Storage Devices:
    Unidade de disco, MAXTOR STM3160211AS, Bus Type ATA, Bus Address [0,0]
    Unidade de disco, MAXTOR STM3160211AS, Bus Type ATA, Bus Address [0,0]
    Unidade de disco, Apple iPod USB Device, Bus Type USB
    Universal Serial Bus Controllers:
    Standard Universal PCI to USB Host Controller. Device is working properly.
    Standard Universal PCI to USB Host Controller. Device is working properly.
    Standard Universal PCI to USB Host Controller. Device is working properly.
    Standard Universal PCI to USB Host Controller. Device is working properly.
    Standard Enhanced PCI to USB Host Controller. Device is working properly.
    No IEEE 1394 Host Controller found.
    Connected Device Information:
    IPOD (H:\), iPod nano running firmware version 1.3.1
    All green lights, and as you can see, according to iTunes, NO PROBLEM! Except that it won't recognize the iPod that the disgnistics says exists and reads... ?!?!?!
    If anyone could shed some light on my situation, i would be VERY greatful!

    My IPod Nano will charge when connected to my computer but it won't come up on My Computer or iTunes. So I can't update the songs. I've already tried reseting the iPod. Does anybody know what I can do to fix it.

  • Envy 17 HDMI won't recognize mutliple displays

    I've got a brand new HP Envy 17 j000 Quad Edition laptop.Device manager is showing two display adapters - one for the onboard intel HD graphics and one for the nVidia 740 GT adapter. When I try to connect an external monitor via the display port (HDMI) on the monitor, the system won't recognize it. Two questions:
    Why is the internal Intel HD Graphics taking precedence over the nVidia? Typically I would set up multiple displays by this driver, but the Intel HD is the one showing the access ports - and only recognizing the internal connection and a VGA connection (which this system doesn't have).
    Is there a preferred connection method - VGA/DVI/DIsplay port? I have the correct display port adapter and a new HDMI cable - both are new.
    thanks -  David B.

    Welcome to the HP Forum David.
    Below might be part of what you seek.
    =====================================================================================
    Here is a bit of information on the Displayport / HDMI question:
    Display Port // DP-Audio-User-Guide-v1 PDF
    DisplayPort.org FAQ
    TechRadar.com – HDMI vs DisplayPort – which is best?
    It may not directly solve your issue; it should help a bit with the background you might need to find a resolution.
    =====================================================================================
    Single External Monitor - that is, connect one external monitor to your computer
    Sometimes the issue is simply resolution - you might therefore be able to duplicate the main computer screen, but not extend it over to the external monitor.
    Resolving HDMI Display and Sound Issues
    =====================================================================================
    Kind Regards,
    Dragon-Fur

  • My ipad currently has ios 5.1.1 and won't recognize any available update for ios 6.  I have tried on the ipad and connected to itunes and both say up to date.  How to I update to ios 6?

    My ipad currently has ios 5.1.1 and won't recognize any available update for ios 6.  I have tried on the ipad and connected to itunes and both say up to date.  How to I update to ios 6?

    See the chart below to determine whether you can upgrade your device and what you can upgrade to. If you do not have a Software Update option present on your iDevice, then you are trying to upgrade to iOS 5 or higher. You will have to connect your device to your computer and open iTunes in order to upgrade.
    IPhone, iPod Touch, and iPad iOS Compatibility Chart
         Device                                       iOS Verson
    iPhone 1                                      iOS 3.1.3
    iPhone 3G                                   iOS 4.2.1
    iPhone 3GS                                 iOS 6.1.x
    iPhone 4                                      iOS 6.1.x
    iPhone 4S                                    iOS 6.1.x
    iPhone 5                                      iOS 6.1.x
    iPod Touch 1                               iOS 3.1.3
    iPod Touch 2                               iOS 4.2.1
    iPod Touch 3                               iOS 5.1.1
    iPod Touch 4                               iOS 6.1.x
    iPod Touch 5                               iOS 6.1.x
    iPad 1                                          iOS 5.1.1
    iPad 2                                          iOS 6.1.x
    iPad 3                                          iOS 6.1.x
    iPad 4                                          iOS 6.1.x
    iPad Mini                                     iOS 6.1.x
    =====================================
    Select the method most appropriate for your situation.
    Upgrading iOS
       1. How to update your iPhone, iPad, or iPod Touch
       2. iPhone Support
       3. iPod Touch Support
       4. iPad Support
         a. Updating Your iOS to Version 6.0.x from iOS 5
              Tap Settings > General > Software Update
         If an update is available there will be an active Update button. If you are current,
         then you will see a gray screen with a message saying your are up to date.
         b. If you are still using iOS 4 — Updating your device to iOS 5 or later.
         c. Resolving update problems
            1. iOS - Unable to update or restore
            2. iOS- Resolving update and restore alert messages

  • My MBP won't recognize my external hard drive

    I have an external hard drive that used to work just fine on my MBP, but now it won't recognize it. When I plug it in (USB), the green light turns on the hard drive, but nothing happens on my MBP. Maybe it is recognizing but not letting me know? I did check disk utility but it's not there either.

    Drives "unmounted" sometimes suffer volume structure damage or similar. Sometimes it's correctable without re-formatting the drive, but not always. Depending on whether or not it contains stuff you want to keep, I'd think you have two choices:
    1. If you don't mind losing what's on it: Reformat the drive (which will erase the contents), using Disk Utility, or just accept the "initialize" option you are offered.
    2. If you want to try to retain the drive's contents, you'll have to try to repair the disk by whatever means available to you. Disk Utility (which is part of the OS, so you own it already), DiskWarrior, and TechTool Pro may be able to detect the drive. If so, try to Repair Disk, Repair Volume Structure, etc. If the disk can't be recognized, you'll probably have to resort to the previous method.
    But if this doesn't work, wait for more advice before doing anything rash, as others may think of things I didn't.

  • My cd/dvd drive won't recognize my cd pavillion dv4

    Every time I put a CD or DVD into my CD/DVD drive, it won't recognize it. It "thinks" for about a minute and then stops. Sometimes if I open and close it will work but not always. I have a Pavillion dv4 with windows 7 that I bought in November 2009 (but my entire hard drive was replaced in May 2011)

    Hi,
    Please try the following method to fix first:
       http://support.microsoft.com/mats/cd_dvd_drive_problems/en-us
    Hope this helps.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • G3 won't recognize Internal IDE hard drive!

    I'm trying to resuscitate a B&W G3 mac (rev. 1) from a Goodwill, and I've gotten it to boot from a G3 installation CD with OS 8 on it, but it won't recognize the sole 27GB IBM ATA/IDE drive I have plugged into it. (The previous owner held onto the mac's original drive.) My drive used to be the master drive in my Quicksilver G4. (I erased and reformatted the drive prior to moving it out of the G4.) I've tried adjusting the drive's jumper configurations, but no matter what, the Mac won't recognize the drive & allow the OS to be installed on it.
    Why is this happening? Is this some kind of logic board failure? Will I need to reformat my drive in some special way? Will I see results if I invest in a ATA-133/100 PCI controller card and plug my drive in there?
    B&W G3 300Mhz   Mac OS 8.6 or Earlier   256MB RAM

    When the drive was in the G4, you formatted it as a Mac OS Extended (HFS+) volume, which is imperative with a drive of that size. If formatted as a Mac OS Standard (HFS) volume, the drive's storage capacity would be squandered with small files parked in excessively oversized allocation blocks. When you referred to using a G3 CD with OS 8, do you mean OS 8, 8.1, or 8.5.1? A CD with OS 8.0 would pre-date the beige G3s, and OS 8.0 doesn't provide support for HFS+ volumes. If the CD has "G3" printed on it and contains OS 8.1, it's intended for use with a beige G3, because the earliest B&W G3s shipped with OS 8.5.1. If your boot CD has OS 8.5.1, then the problem is undoubtedly related to the Rev. 1 IDE controller's lack of support for large drives. A much-smaller IDE (4 - 8 GBs) drive or a Mac-compatible ATA controller card will solve the problem.

  • MacBook Pro won't recognize 1TB external drive

    Hey team,
    My mid-2010 MacBook Pro won't recognize my WD My Passport 1TB drive.  I was copying files from the drive to my computer when my computer went to sleep (didn't run out of power, just went to standby mode).  Turned computer back on and now it won't recognize the drive.
    It is a USB 3.0 cord (computer is only USB 2.0 and the cord works with other drives) and when plugged in, the light turns on and the disk spins but isn't recognized my this or other computers (also not in Disk Utility).
    Tried a handful of disk recovery programs but nothing wants to 'see' the disk plugged in.
    Thanks for any and all suggestions.

    yes yes yes,   I warn people about WD drives on this link:
    Your dead external hard drive is likely fine! Great hope for your 'faulty' external HD
    theReKleiner wrote:
    What now?
    Only option is to buy the SAME exact HD and swap controller boards,  or pay someone a LOT more $$$ to do the same thing.
    its not soldered there, its just a controller/ SATA  "one piece"
    They do that to save 50 cents in mfg. costs.
    I mention your "issue" in that link.    Which is why you do NOT buy WD ext. HD.
    they make the controller board and SATA card one piece. 
    CURRENT MFG. THAT HAVE controller board and SATA cards as one piece are :  WD USB drives, and Toshiba USB Canvio
    However Toshiba didnt USED to do that, but they started doing it at the end of 2013.
    avoid those 2.
    To avoid that nonsense, buy Hitachi drives in USB.
    Or, the best option:
    Save money and invest in a bare hard drive backup and redundancy plan
    Its cheaper
    less fuss
    more reiable, removes the nasty failure point of SATA card interfaces.
    takes up lot less space.
    Bare hard drives and docks. The most reliable and cheapest method of hard drive data storage, archives, and redundancies
    The best method for your data archives and redundancies, which is also the least expensive, the most reliable, and the most compact option is the purchase of naked hard drives and at least one USB 3.0 HD dock ($40 roughly).
    While regarding Time Machine and your Macbook or desktop, your primary backup is best saved to a conventional USB (or Firewire / thunderbolt) hard drive inside an enclosure, the most important part of your data protection begins after your 1st / primary Time Machine / backup; and these are your secondary (most important) data storage devices, archives and their redundancies.
    However bare hard drives and docks (below) also work perfectly as a Time Machine backup, this is for home use, since the docking station is certainly not very portable as a notebook Time Machine backup device should be; nor should bare HD be packed around with a notebook, rather remain at home or office.
    Six terabytes of 2.5" HD pictured below in a very compact space.
    Bare hard drives and docks have the lowest cost, the highest reliability, and take up the smallest storage space
    Drawbacks:
    1. Care and knowledge in general handling of naked hard drives (how not to shock a bare HD, and how to hold them properly). Not a genuine drawback.
    Advantages:
    1. By far the least expensive method of mass HD storage on a personal basis. Highest quality naked HD can be purchased in bulk very cheap.
    2. Eliminates the horrible failure point of SATA bridges and interfaces between external drives and the computer.
    3. Per square foot you can store more terabytes of data this way than any other.
    4. Fast, easy, no fuss and most simplex method of data storage on hard drives.

  • Problem calling Java method from JavaScript in JSP / ADF

    Hi all,
    In my JavaScript onMouseUp() function, I need to call a method on my Java backing bean. How is this done? Info on the web indicates a static Java method can be called by simply "package.class.staticMethod(...)". but when I put the statement
    "jsf.backing.GlobalRetriever.createBasemap(affectedLayer);"
    I get an error message "jsf is undefined".
    The functionality I'm trying to get is: I have a custom slider control and based on its value, I want to call oracle map viewer specifying a map extent of the (current extent / slider value) to do a zoom in/out. In addition, the slider uses a onMouseMove() function to change the size of the image display so it looks like a dynamic zoom in/out.
    Please assist or let me know if I can provide some additional information. Thanks in advance.
    Jim Greetham

    No. The Java and Javascript in a Faces application are really working in two different universes.
    Java is running on the server. It generates HTML (and sometimes even Javascript) and sends that to the client machine. That's where all your backing beans are.
    Javascript runs directly in the browser. There's no way anything on the server can have access to anything you define in Javascript, unless you explicitly send that information back to the server, either via standard form submission (which only works when someone presses a "Submit" button) or via an Ajax-type call. So otherwise, nothing you define in Javascript will ever be available to a backing bean.

  • How to call Java methods from a Windows application?

    Hello all,
    At our company, we need to integrate our product which is a Java Swing application with a Windows application. Specifically, we are trying to call Java methods that reside in our application from the Lotus Notes email client application, which is a native Windows application. Such that when a user clicks a button in the Lotus Notes email client, it will trigger an event in our Swing application. Is this possible using JNI? Do you know of any resources or references relating to this kind of a project?
    Thanks,
    Mete Kural

    If there is some dll interface that lets Lotus Notes load up and use a DLL, then yes, this should be possible.

  • Having trouble after osi7 on my iPad, I have one contact that won't recognize a number? Also can't move and scale a photo for wallpaper.

    Having trouble after osi7 on my iPad, I have one contact that won't recognize a number? Also can't move and scale a photo for wallpaper.

    Downloads available:
    Suites and Programs:  CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4 | CS3
    Acrobat:  XI, X | 9,8 | 9 standard
    Premiere Elements:  13 | 12 | 11, 10 | 9, 8, 7
    Photoshop Elements:  13 |12 | 11, 10 | 9,8,7
    Lightroom:  5.7.1| 5 | 4 | 3
    Captivate:  8 | 7 | 6 | 5
    Contribute:  CS5 | CS4, CS3
    Download and installation help for Adobe links
    Download and installation help for Prodesigntools links are listed on most linked pages.  They are critical; especially steps 1, 2 and 3.  If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'.

  • JAVA Regex Illegal Characters

    Hello - I am trying to find a list of all illegal characters which have to be escaped in JAVA Regex pattern matching but I cannot find a complete list.
    Also I understand that when doing the replaceall function that there is a special list of characters which can't be used for that as well, which also have to be escaped differently.
    If anyone has access to a full complete list as to when to escape and how I would greatly appreciated it!
    Thanks,
    Dan

    I also noticed this below link:
    http://java.sun.com/docs/books/tutorial/extra/regex/literals.html
    It said the following characters are meta-characters in regex API:
    ( [ { \ ^ $ | ) ? * + .
    But it also says the below:
    Note: In certain situations the special characters listed above will not be treated as metacharacters. You'll encounter this as you learn more about how regular expressions are constructed. You can, however, use this list to check whether or not a specific character will ever be considered a metacharacter. For example, the characters ! @ and # never carry a special meaning.
    Does anyone know if there would be any issues if I escaped when a character didn't need to be escaped?

Maybe you are looking for

  • Error in running jsp file which contains inner class,help !

    Environment ias sp4 for windows2000 Error: try to access class jsp.APPS.bsteelWZ.order.OrderMgmtMain$1$sOrderHelper from class jsp.APPS.bsteelWZ.order.OrderMgmtMain OrderMgmt.jsp contains a class named sOrderHelper. It's all ok on ias sp2 for solaris

  • Typing

    I am using lumia920 while typing any mail or message if any correction required editing is difficult at particular word. It should have cursor like BB mobile or Samsung mobile has which helps in editing words. or if any setting missing kindly guide.

  • Firefox 3 Crash on Mac OS X Leopard

    I'm a professional user of Windows and Linux (Ubuntu). But last week, I decided to switch to the Mac and I buy a Mac book Pro. I install the Firefox 3 on it. But after one day, when I installed some add-ons, my Firefox crashed. When I click on it, it

  • Intel 5100 stop working occasionally

    OS: happend both on Vista Home Basic and XP SP3 Machine: X200 Driver: happened both with Lenovo pre-install and Intel new driver happened both w/ or w/o Access Connection Wireless Router: ordinary router that I used for a few years. all other noteboo

  • Error 16 in CS5 Design Premium

    I downloaded the CS5 trial yesterday and installed it just today, when installing everything is great but when I get to open the applications (Photoshop, Illustrator, InDesing etc.) I get the error 16 I already tried the various "solutions" and none