Skip to content
Advertisement

Tag: regex

Why can’t I make a group repeat in regex Java?

I have a regex I want to construct for validating the UNC syntax, which is: \serversharedfolderpath I don’t care about the server or folder characters, I exclusively want to validate the thing1thing2maybe3 syntax, the server and folder names will be validated separately. This is what I have so far: These are my tests: MATCH – \servermultiplefoldersexamplepath FAIL – \server\multiplefoldersexamplepath SHOULD

How to make a regular expression for this seemingly simple case?

Is it possible to write a regular expression that works with String replaceAll() to remove zero or more spaces from the end of a line and replace them with a single period (.). For example, a regex that will make these (non-exhaustive) test cases pass: I know I can do it with replaceFirst(” *$”, “.”), but I’m wondering if it

Regex split string in double quotes

I have the following string I need to split by double quotes. below is the sample string When I try to split the string by double quotes, knowing that some quotes can be empty I tried the following : String[] split = raw.split(“”(\w\s+|\s+)””); it is close but I seem to be missing something. Answer You can simply split it on

how pattern syntax exception works

how do I use the following statement in try n catch block to chk if the name is valid and display error msg if any? and how to use PatternSyntaxException Answer You don’t need a try…catch to check if the name is valid. The line you wrote: NAME_PATTERN.matcher(name).matches() returns a boolean, true if it matches and false if it doesn’t.

Remove backslash before forward slash

Context: GoogleBooks API returing unexpected thumbnail url Ok so i found the reason for the problem i had in that question what i found was the returned url from the googlebooks api was something like this: Going to that url would return a error, but if i replaced the ” /”s with “/” it would return the proper url is

Advertisement