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
- I need the BIRT.war that is compatible with Java 17 and Tomcat 10
- Creating global Class holder
- No method found for class java.lang.String in Kafka
- Issue edit a jtable with a pictures
- getting error when trying to launch kotlin jar file that use supabase "java.lang.NoClassDefFoundError"
- Does the && (logical AND) operator have a higher precedence than || (logical OR) operator in Java?
- Mixed color rendering in a JTable
- HTTPS configuration in Spring Boot, server returning timeout
- How to use Layout to create textfields which dont increase in size?
- Function for making the code wait in javafx
- How to create beans of the same class for multiple template parameters in Spring
- How could you print a specific String from an array with the values of an array from a double array on the same line, using iteration to print all?
- org.telegram.telegrambots.meta.exceptions.TelegramApiException: Bot token and username can't be empty
- Accessing Secret Variables in Classic Pipelines through Java app in Azure DevOps
- Postgres && statement Error in Mybatis Mapper?
Related Questions in REGEX
- Python and regex, can't understand why some words are left out of the match
- Special access rule in an .htaccess file for IP addresses, authorized only for one directory structure
- regex working not as expected javascript, displays wrong values
- Clarity on how can `.*` match all strings?
- IIS Rewrite Module exclude bots but allow GoogleBot
- Regex skipping delimiter is there is / before it
- How to ignore case in regexp mapping in a .htaccess rewrite rule?
- Select all lines after last occurrence of a certain character
- Segregate class names using regular expresions
- Regex to match binary literal number in re2c format
- why the perl regular expression is not identifying the value
- Trying to run subprocess commands with carriage returns and newlinees
- `Backward slash + b` does not work as expected on regex
- Extract 15 words before and 8 words after each 9digit number from a text file using regular expressions in python
- How to migrate this regex to JavaScript
Related Questions in FILEPATH
- R: Walk up a directory tree up to a particular directory
- path.split strange behavior
- how to access OpenFileDialog with Streamwrite?
- Can't link local picture file to HTML on chromebook
- FileInfo path not wokring in asp.net core delpoyed in ubuntu machine
- Problem with losing upload path on refresh in ASP.NET Web Forms
- Tkinter: print (.txt) filepath to text widget AND (.txt) file content to scrolledtext widget in the same gui with one filedialogue access
- Os path Join Two args
- How to load and get XML File path in a build unity Android project
- The Image won't be displayed for some reason in php
- How can I get Absolute file path at started content:// type Uri on Non-Media Type
- Convert Local File URL to File Path
- Can you specify a file path in the CSS file relative to the HTML file?
- Ruby On Rails - Redirect_to |format| not working
- Save file path without specifying User
Related Questions in DRIVE-LETTER
- Finding Drive Letter by Disk Number, Partition Number, and Label using AutoIt
- Assign drive letter to CD-Drive using PowerShell
- How to assign available driveletter by mapping type name using powershell?
- How to navigate to a file in an unknown drive letter (powershell)
- how to assign output from command to variable in command prompt
- C++ Problem not return network drive (Z:/) , with running the program in RunAsAdmin mode
- How to find folder when drive letter is unknown and folder path is random/unknown. using wmic logicaldisk get caption in Batch File?
- Aquiring USB Drive Letters from command and use them as choice variables
- Batch file change a drive letter string in a log file
- Get Drive-Letter of Storage Drive By Name/ID in Python
- Slow to unmap network drive letter
- Spring Framework fails on paths with Windows Drive Letters
- Batch File Assign Drive Letter
- Convert from Windows NT device path to drive letter path
- Programmatically set EBS Volumes Windows Drive Letters using Terraform, Chef or Powershell
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 # Hahtags
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.)