Basically, I'm getting a file path from a string inside of a CSV file. However, for some reason, the program generating the CSV file removes the colon from the string, so I end up with a file path that does not work inside of Java. The typical output is /x/Rest/Of/Path where x is the drive letter, but may occasionally be x/ instead of /x/. Basically, I need to add a colon after the drive letter if there isn't one already; changing either /x/ or x/ to x:/. I'm sure this is mostly done through regex, but I'm still trying to figure out the basics of regex myself, so I'm not sure how to write it. Thanks in advance for any help.
Add colon to file path after drive letter (ie: change /c/ or c/ to c:/) in Java
1.6k Views Asked by DGolberg At
1
There are 1 best solutions below
Related Questions in JAVA
- Add image to JCheckBoxMenuItem
- How to access invisible Unordered List element with Selenium WebDriver using Java
- Inheritance in Java, apparent type vs actual type
- Java catch the ball Game
- Access objects variable & method by name
- GridBagLayout is displaying JTextField and JTextArea as short, vertical lines
- Perform a task each interval
- Compound classes stored in an array are not accessible in selenium java
- How to avoid concurrent access to a resource?
- Why does processing goes slower on implementing try catch block in java?
- Redirect inside java interceptor
- Push toolbar content below statusbar
- Animation in Java on top of JPanel
- JPA - How to query with a LIKE operator in combination with an AttributeConverter
- Java Assign a Value to an array cell
Related Questions in REGEX
- Check for numeric value with optional commas javascript
- CSV to XML XSLT: How to quote excape
- How can I determine the index of the same set of characters between two strings that are of different lengths?
- Max 3 digits, up to 3 decimals
- Regex for SQL insert query
- Javascript Regex to get specific string from two differently-formatted text blocks
- JavaScript differences beetween new Regex('regex', 'flags') and /regex/flags
- Java replace every Nth specific character (e.g. space) in String
- c# regex spain mobile phone
- Perl Regex: Merge multiple one-character substrings
- Using .css("background-color") for comparison jQuery/Js
- Unexpected NoReverseMatch error when using include() in urls patterns
- RegEx for all the javascript code except comments
- Regex: how to separate username:password?
- Customising a RegExp for international phone numbers
Related Questions in FILEPATH
- Java StreamSource from file in web application project
- In Angular project reference to php script give 404 (Not Found) locally, but works on live site
- Finding the file path (server directory) from using Firebug
- PHP Saving and outputting GD Lib image - relative and absolute paths
- Only writing the relative filename from the full file name c#
- Python: too many joins()?
- Getting application folder path on MeteorJS?
- XSLT filePath with document as variable
- PDF file path is incorrect
- Recursively expand and search pattern of specific subdirectories
- How to have ImageIO.write create a folder path as needed
- Convert path not used in the R animation package
- Scala - write Windows file paths that contain spaces as string literals
- I'm writing C# code that has to run on windows and linux (under mono). Easy way to handle file paths on both?
- How to set a specific path while file uploading using php
Related Questions in DRIVE-LETTER
- Drive Letter vs. DevicePath
- Get partition name from drive letter and vice versa
- Java Servlet absolute paths outside webfolder [ Windows & Linux ]
- How do i get drive letter for a running form
- how to assign output from command to variable in command prompt
- How to navigate to a file in an unknown drive letter (powershell)
- Aquiring USB Drive Letters from command and use them as choice variables
- Why does _splitpath_s() take custom sized string buffer for returning drive letter?
- Spring Framework fails on paths with Windows Drive Letters
- C++ Problem not return network drive (Z:/) , with running the program in RunAsAdmin mode
- How to assign available driveletter by mapping type name using powershell?
- Assign drive letter to CD-Drive using PowerShell
- Find current diskpart volume number in .bat
- Batch File Assign Drive Letter
- Get Drive-Letter of Storage Drive By Name/ID in Python
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Here, try this, and study it to learn how it works:
Here's a guide:
^is known as an anchor. It matches the very beginning of the string. Without it, this regex would also match/foo/C/Rest/Of/Path, and we don't want that.?can mean various things, depending on where it appears. If it doesn't immediately follow an open-parenthesis(, doesn't immediately follow a quantifier*,+, another?,{n},{m,n}, doesn't appear inside a character class[], and isn't escaped\?, then it is a quantifer, meaning, "0 or 1 of the previous entity," in this case, the/. Think of it as the "optional" operator.[CDEFGH]is known as a character class. It means, "Any one of these characters." You can negate a character class like so:[^CDEFGH]; this would mean, "Any one character but not these." If you would like to accept any capital letter, then you could use a range:[A-Z]. If you would like to accept any letter, then:[a-zA-Z].$1,$2,$3, and so on. (So, you can capture more than one group; each capturing group is numbered by the order of its opening parenthesis.) In the above example, note that I captured the/?as well, so if the slash existed, then it would exist in the output too, and if not, then not.Happy learning!
EDIT
I should have exemplified a simpler approach to start. My apologies. This will do as well:
The use of a compiled pattern only adds to efficiency. For example, if you were going to replace an array of 10,000 paths, you'd compile the pattern once, then use the matcher to replace per path in a loop. (Without compiling, the engine ends up having to parse the pattern from scratch for each path encountered.)