Regular expressions, characters unallowed in file names

trying to take a url and turn it into a file name by grabbing the last bit of the string that doesnt have any characters that arent allowed in file names, but this keeps returning the same sting over and over again "://"
System.out.println("\n" + filename + "\n");
Pattern pattern = Pattern.compile("[\\\\/:\\*\\?\\\"<>\\|][^[\\\\/:\\*\\?\\\"<>\\|]]+");
Matcher matcher = pattern.matcher(filename);
while (matcher.find())
filename = matcher.group();
System.out.println("\n" + filename + "\n");

Is "filename" a string, or an array of strings? Assuming it's just a string, try this: System.out.println("\n" + filename + "\n");
Pattern pattern = Pattern.compile("[^\\\\/:*?\"<>|]+$");
Matcher matcher = pattern.matcher(filename);
if (matcher.find())
  filename = matcher.group();
  System.out.println("\n" + filename + "\n");
}

Similar Messages

  • Regular Expression for a Person's Name

    Hi,
    I am using the org.apache.regexp package and trying to find the regular expression for a person's name. It allows only the alphabetic string.
    I tried [a-zA-Z]+. But this also accepts the thing like "BUSH88", which is not what I want...
    Can anybody help me figure this out?
    Thanks in advance,
    Tong

    Hi,
    I am using the org.apache.regexp package and trying to
    find the regular expression for a person's name. It
    allows only the alphabetic string.
    I tried [a-zA-Z]+. But this also accepts the thing
    like "BUSH88", which is not what I want...
    Can anybody help me figure this out?
    Thanks in advance,
    Tongtry this:
    ^[a-zA-Z]+$
    the ^ represents the start of the String and the $ represents the end.
    So the expression is saying: "between the beginning and the end of the String there will only be alphbetical characters"

  • Destination file characters too long (File names) , while copying from one external to another

    I have a external my book fat32 formated and a new mybook ntfs formated external as well.  Now when I copy my files from the fat32 to the ntfs external all files copy fine but some give that destination location file characters are too long, meaning that the file names are too long.  Now I could change the file names but that would conflict with programs that need that file name.  I am using vista ultimate and would like to copy all the files over from the fat32 to ntfs so I can reformat the fat32 to ntfs.  The files got on the ntfs from a simple drag and drop from my IDE NTFS internal hard drive.
    I hope you guys to tell me what to do.
    Thank you :)

    Here's the fix....for error message "your file name is too long to be copied, deleted, renamed, moved" :
    1.   problem is this: the "file name" has a limit on number of characters.....the sum of characters really includes the entire path name; you gotta shorten it first (i.e, if the total number of characters in the file name + Path name are over the
    limit, the error appears).  The deeper your file folder sub levels are, the more this problem will come up, especially when you copy to a subfolder of a subfolder/subfolder of another path ...adds to character limit)
    2.  How do you know which combined file names + path names are too long if  you are in the  middle of a copy operation and this error pops up?  Some files copied but the "long files error message" says "skip" or "cancel" ... but not which
    files are the "too long" ones.  If you hit "skip" or "cancel" the "too long" files are left behind...but are mixed in with non-offender "good" "short name" files.   Sorting thru 1000s of "good" files to find a few "bad" ones manually is impractical.
    3.   Here's how you sort out the "bad" from the "good":
    4.    Let's say you want to copy a folder ..."Football" ...that has five layers of subfolders; each subfolder contains numerous files:
      C:/1 Football / 2 teams/ 3 players/ 4 stats/ 5 injuriessidelineplayerstoolong 
           There are five levels root "1 football" with subfolders  2, 3, 4 and lastly "5 injuries"
    5.    Use "cut" and "paste"  (for example to backup all five levels to a new backup folder):
           select "1 football" ....cut....select target folder....paste 
           ("cut" command means as the files are copied to the target destination, the file is deleted from the source location)
          Hint: avoid "cut" and "paste" to a target folder that is itself a sub/sub/sub folder ...that compounds the "characters over the limit" problem ...because the characters in the sub/sub/sub folder are included in the "file name
    character limit"...instead "paste" to a C:/ root directory.
           Suppose in the middle of this operation...error pops up: "5 files have file names that are too long"  Skip or cancel?
           select "skip"  ...and let operation finish
    6.    Now go back and look at the source location: since the software allows only the "good" "short name" files to be copied (and because you "skipped" the "bad" "Long name" files so they are not copied or deleted) ...all that remains
    in the source location are the "bad" "long name files" (because "good" ones were deleted from the source location after the "cut" operation...the bad ones stick out like a sore thumb.
    7.   You will find ....all that remains in source folders are: the "bad" "too long" files; in this example the "bad" file is in level 5:
          C:/ 1 football / 2 teams /3 players /4 stats /5 injuriessidelineplayerstoolong
    8.   select folder 5 injuriessidelineplayerstoolong (that's right...select folder, not file) gotta rename the folder first.
    9.  hit F2 rename folder..folder name highlighted...delete some of the letters in the folder name:
           like this:   5 injuriessidelineplayers  ....you should delete 'toolong'....from the folder name
    10.  then go into folder 5....and do the same operation ...with the too long file name:
            hit F2 rename file....file name hightlighted...delete some of the letters
               like this:  injuriessidelineplayers.....you should delete 'toolong' from the file name
    11.  Now..."cut and paste"  the renamed file to the target backup folder.  
    The Error message will pop up again if you missed any "bad" files....for example, it will indicate "5 files too long" ....then repeat process 5 times until you fix all of them
    12.     Finally, copy the target destination files back to the source location (when you are certain all source location file folder locations are empty) 

  • Re number of characters in a file name with leopard.. 10.5.3

    re number of characters in a file name with leopard.. 10.5.3
    Is there a limit? in a file or directory name?

    hfs+ == hfs extended, the default filesystem on a current mac...
    http://en.wikipedia.org/wiki/HFS_Plus

  • Javamail API doesn't support special characters in attachment file name

    Hi,
    We are using Java Mail API to retrieve the attachment's file name, but it sometimes returns the file name as junk character (if the attachment contains special characters) and it is not able to return original file name for some attachments:
    Our code sample :
    void getFileName(Part part) {
    String fname=null;
    fname = part.getFileName();                          
    Actually the problem is with the attachment file name which contains special character. For example below is the attachment file name (please find the sample attached file which is causing this issue):
    Sample – 1234abc.doc
    From above you could see the file name contains a special character (Sample – 1234abc.doc), i.e. The character ‘–’ is not a regular hyphen character, it’s a special character. Hence the Java mail API returns the name as below:
    Sample ? 1234abc.doc
    So the special character is being replaced with ‘?’ symbol. But if I store this file in local folder and try reading the file name using Java IO packages, it returns the file name without adding ‘?’ symbol.
    Is there any way to handle such kind of special characters in Mail API?
    Regards,
    Vinodh

    We dealt with this issue in a private email conversation.
    JavaMail is returning the correct data for the filename.  The problem is in the way the filename is being displayed.

  • Non US-ASCII characters in download file names

    I am trying to implement a simple file download in a JSP, and trying to get IE, Firefox and Opera to all display and handle non US-ASCII characters in the suggested download file name. Only concerned with Windows platform for now. Here's the code I am currently using:
    String agent = request.getHeader("USER-AGENT");
    if (null != agent && -1 != agent.indexOf("MSIE"))
    String codedfilename = URLEncoder.encode(cfrfilename, "UTF8");
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition","attachment;filename=" + codedfilename);
    else if (null != agent && -1 != agent.indexOf("Mozilla"))
    String codedfilename = MimeUtility.encodeText(cfrfilename, "UTF8", "B");
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition","attachment;filename=" + codedfilename);
    else
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition","attachment;filename=" + cfrfilename);
    }This URL encodes the file name if the browser is IE, MIME encodes it if the browser is Mozilla, and sends plain UTF-8 (the encoding of the JSP) for all other browsers. I get "cfrfilename" from translated properties files, and the string can contain characters from any character set - Chinese, Thai, Korean, etc.
    This code works correctly for IE - the file name is displayed correctly in the file Save as dialog, and it is saved correctly on disk, no matter which character set is used.
    For Firefox, the file name is displayed correctly in the file Save as dialog, but it is only saved correctly to disk if the file name is in a character set supported by the system locale. This seems to be a known Firefox bug (not fully using the Windows Unicode APIs), so nothing I can do about that.
    Nothing seems to work for Opera, however - I cannot get the file name to display correctly in the file Save as dialog, no matter which method I use (I have tried URL encoding and MIME encoding in addition to the plain UTF-8).
    Has anybody implemented something similar that works for at least these 3 browsers?

    I tested your code today,
                         dialog           save           open
    Firefox 1.5          OK                 OK               OK
    IE 6.0                OK                 OK                NGdailog: filename show in download popup dialog
    save: save to disk from dialog
    open: open directly from dailog

  • Strange characters in downloaded file names

    Everytime I download a file that has a space or some kind of accent in it's name, I get some bizarre characters. For instance I get a %20% instead of every space in the file name...
    I guess it's an encoding problem but I haven't been able to find what the cause of the problem is or how to fix it. I've tried changing the default encoding in the Preference but doesn't change anything. I also tried to change the Language in the International System Preference panel, with no results.
    I've had this problem forever, but it's really frustrating to get this with what is supposed to be the most advanced operating system in the world. I've been bragging to my PC friends (well, they're not really friends, more like acquaintances) since 1984 about having no problems with accents, spaces, etc. in file names... and now...
    Please help.

    Everytime I download a file that has a space or some
    kind of accent in it's name, I get some bizarre
    characters. For instance I get a %20% instead of
    every space in the file name...
    It's not an encoding or language problem. Spaces are not allowed in urls, they must be replaced by %20, which is the escaped Unicode value for that character. Many servers do not accept spaces in the names of uploaded files, so the people uploading them delete spaces or replace them by underscores. But some servers do accept spaces in uploads and then replace them by %20. The same goes for accented characters.
    I don't think that there is anything unusual about what you are seeing, or that there is anything you can do about it.

  • Special Characters in the file name in Data Driven Subscription via File Share

    Hi,
    I am trying to create a Data Driven Subscription with option to delivery as  windows file share in SQL server 2005. I need to save the report as a pdf with the following file name  '[City] City_Name', but it errors out and it is because of the
    Square Brackets. Is there any way i can save the file using the Square brackets as i mentioned above.
    I am using a query to get the filename and filepath. It works fine as long as i do not have [], but i need to save the file as i mentioned along with the Square Brackets.
    Please help.

    Hello,
    I can reproduce the issue on my test environment: When I create a Data Driven Subscription and specify the report name by get from a subscription delivery table, and the value of the "report name" column contains square brackets. The subscription failed
    with following error in the error log:
    ERROR: Error occurred processing subscription ab9523a6-0256-4607-b818-a7666204d018:
    The file name is not valid. Avoid using special characters such as /\?*:<>|+,[]"& in the file name.
    notification!WindowsService_1!1f24!05/30/2014-15:31:02:: i INFO: Notification 0cf5a356-3172-4108-9d8c-58ea81a0b80a completed.  Success: False, Status: The file name is not valid. Avoid using special characters such as /\?*:<>|+,[]"& in the
    file name., DeliveryExtension: Report Server FileShare, Report: Report6, Attempt 0
    It seems that the behavior is by design. please avoid using square brackets as file name. Maybe you can try to use parentheses () instead.
    Regards,
    Fanny Liu
    Fanny Liu
    TechNet Community Support

  • Firefox doesn't reconvert special characters in the file names when download a file with any special characters in the file name

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [/questions/815207]</blockquote><br>
    if i try to download a file with any special characters in file name (e.g. File_Name.pdf), it doesn't reconvert them from the "sanitize url" process and download the file an incorrect name (e.g. File%5FName.pdf).
    This is really annoying.
    Thank you for your patient

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    * [[Troubleshooting extensions and themes]]

  • Illegal characters in topic file names

    Robohelpers,
    I imported vintage MS Word files (dating from the early 90s)
    in to RoboHlep HTML. The topics generated correctly, but some of
    the characters in the the file names converted incorrectly, and are
    not recognized inside the program and the links to these topics are
    dead.
    The most common glitches:
    - The EN dash converts to an underscore, e.g. _–_
    appears on the disk as ___
    - The apostrophe converts to Æ
    The Topic list shows the correct characters. But since they
    don't agree with the physical file names, RoboHelp marks the icon
    with an "X".
    What's the best way to correct his situation, if you have
    hundreds of topics to deal with?
    I search for a solution without success. I can't believe that
    no one has encountered this issue before.
    Best regards,
    Charles Arnold
    MetLife DI
    Tampa, Florida
    I found a utility call "Rename" by on an Adobe web site, but
    it generated DLL conflict in my computer.

    Hello Charles -
    Are you posting to the correct forum? I ask because you
    posted that you're importing into RoboHelp HTML - this is the
    WebHelp forum. However, your situation can also occur with WebHelp.
    The problem is the Word files used Microsoft extended characters,
    the so-called "Smart" characters but that was dumb to use for
    anything that is converted to HTML. Do a mass search and replace
    for the "Stupid" quote, apostrophy and EN-dash and correct them to
    true HTML valid characters.
    Regards,
    GEWB
    See:
    http://tatumweb.com/typerat/ansirodent.htm

  • Allowable Characters in the file names within Oracle iFS

    What characters are allowable in file names within Oracle iFS?
    Are slashes (/ \) possible?
    Thanks,
    Sai Mummalaneni.

    Be carefull with file and directory names in iFS. You might be able to create folders and add document to it through the web interface that the windows explorer interface might not be able to interpret. Like a directory named '.'.
    Tamas Szecsy

  • How do I remove spaces and special characters from the file name during rendering?

    I understand that I can set LR_renamingTokensOn to true, but I would like to replace all spaces in the file name with an underscore and remove characters not in the range A-Z and 0-9. What's the easiest way to achieve this?

    local photo = catalog:getTargetPhoto()
    local sesn = LrExportSession {
        photosToExport = { photo },
        exportSettings = {
            -- ... (determine from export preset) - whatev you want, just be sure you set export directory: LR_export_destinationPathPrefix
            LR_tokens = "{{custom_token}}",
            LR_tokenCustomString = LrPathUtils.removeExtension( photo:getFormattedMetadata( 'fileName' ) ):gsub( "[ %c]", "" ) -- remove spaces and control characters
    sesn:doExportOnNewTask()

  • Regular expressions read from a file?

    Hello,
    I'm trying to read a bunch of string literals from a file, and then replace their appearances in another string. It works, except when I have special characters in the file, like this:
    (hello)
    When I use that in Pattern.compile(), it obviously thinks that the parenthesis are not literal. So, I edited my text file and changed the line to:
    \\(hello\\)
    No change. It will not match the string at all. I've even tried this (just out of deperation):
    \\\\(hello\\\\)
    It just doesn't seem I can escape it right if the expression is being read from a file.
    What am I doing wrong?

    Another idea: I tried the following
    import java.io.*;
    public class RegexTest {
        public static void main(String[] args) {
            try {
                File input = new File("pattern.txt");
                FileReader in = new FileReader(input);
                int c;
                StringBuffer buf = new StringBuffer();
                try {
                    c = in.read();
                    while (c != -1) {
                        if (!Character.isWhitespace((char)c)) {
                            buf.append((char) c);
                        c = in.read();
                    System.out.println(buf.toString());
                } catch (IOException iox) {}
                String previous = "(hello) test test test";
                System.out.println(previous);
                System.out.println(previous.replaceAll(buf.toString(), "test"));
         } catch (FileNotFoundException nfnx) {}
    }and it works properly.
    I found out that if the input line with the "\(hello\)" pattern ends with the usual CRLF the only way to have the expected results is to filter out the extra characters (using the !Character.isWhitespace((char)c) test).
    Does this give you any help?

  • Regular Expressions and Double Byte Characters ?

    Is it possible to use Java Regular Expressions to parse
    a file that will contain double byte characters ?
    For example, I want a regular expression to match the following line
    tag="double byte stuff" id="double byte stuff"

    The comments on the bytes/strings were helpful. Thanks.
    But I'm still confused as to what matching pattern could be used.
    For example a pattern like:
    [A-Za-z]
    I assume would not match any double byte characters.
    I also assume the following won't work either:
    [\\p{Alpah}]
    because it is posix - US-ASCII only.
    So how do you say "match the tag, then take any characters,
    double byte, ascii, whatever, then match the text tag - per the
    original example ?

  • Regular expressions for file/FTP transport within OSB.  How?

    The OSB transport/polling guides say for the FILE, FTP and SFTP transports that the "File Mask" can be a Regular Expression but I can't get it to pick up files this way. Is there some trick to enabling regular expression mode or some strange syntax required?
    For example I set up a very simple pattern of [A-Z]+ which should match any filename with one or more uppercase alphabetic characters only, but it does not pick up anything. It seems only to support the usual wildcard * operator in the non-regular expression mode.
    Any help much appreciated.

    Good point, but if you think about this description, you have to realize it just doesn't make sense. Again ...
    Enter a regular expression to select the files that you want to pick from the directory. The default value is \*.*The problem is that \*.* is not a regular expression at all. :-)
    1. The documentation is a mess in this particular point.
    2. FTP servers (at least those I have experienced) don't have a support for regular expressions.
    So I guess you can use only wildcards and not regular expressions with FTP transport.

Maybe you are looking for

  • How to resolve Update installation issues for Photoshop CS6

    I keep getting install error u44m1u5 when attempting to install Photoshop camera raw update 7.2   How do I resolve this?  I also get same  error  code for adobe bridge cs6 5.0.1.1 update and extension manager 6.0.4 update.  Adobe application manager

  • Recording audio ONLY from a DVD into iTunes

    Hi, I'm new to macs having just got an iMac G5. So far I love it and it's loads better than any windows based system I've had. I'm wondering if it is possible to record the audio only from some music DVD's I have into iTunes...can anyone help or is t

  • Why did I add and album and it when in several times but only 1 to 3 songs on album at a time

    Added new albums. Some separated songs and and made new folders out of them. I had my own bluegrass music i down loaded from CD and they all dissappeared. I have lots of Christmas songs on ipod but I really don't want to hear them till aleast Thanksg

  • Delete apps

    How does one delete apps on i pad taking too long to load?

  • Could Anyone Help Me Comment This Coding

    var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError, false, 0, true); loader.load(new URLRequest("game.xml")); ii Need To Comment My Cod