I want to create a Java regular expression to grab all words that start with a capital letter then capital or small letters, but those letters may contain accents. Examples : Where Àdónde Rápido Àste Can you please help me with that ? Answer Regex: Java string: Explanation: Caveat: This only works correctly in very recent Java versions (JDK7); for
Tag: regex
Splitting strings through regular expressions by punctuation and whitespace etc in java
I have this text file that I read into a Java application and then count the words in it line by line. Right now I am splitting the lines into words by a But I know I am missing out on some words from the text file. For example, the word “can’t” should be divided into two words “can” and
Java Regex: matches(pattern, value) returns true but group() fails to match
I have an odd problem with a regular expression in Java. I tested my Regex and my value here and it works. It says there are 3 groups (correct) the match for the first group (not group zero!) is SSS, …
Regular expression to match unescaped special characters only
I’m trying to come up with a regular expression that can match only characters not preceded by a special escape sequence in a string. For instance, in the string Is ? stranded//? , I want to be able to replace the ? which hasn’t been escaped with another string, so I can have this result : **Is Dave stranded?** But
Regular expression with variable number of groups?
Is it possible to create a regular expression with a variable number of groups? After running this for instance… … I would like to have something like m.group(1) = “c” m.group(2) = “d” m.group(3) = “d” m.group(4) = “c”. (Background: I’m parsing some lines of data, and one of the “fields” is repeating. I would like to avoid a matcher.find
How to filter string for unwanted characters using regex?
Basically , I am wondering if there is a handy class or method to filter a String for unwanted characters. The output of the method should be the ‘cleaned’ String. Ie: Expecting result would be: A better example: I expect the result to be: Because, i let the cleaner know that ‘ ‘, ‘*’, ‘#’, ‘&’ and ‘_’ are dirty
Removing all whitespace characters except for ” “
I consider myself pretty good with Regular Expressions, but this one is appearing to be surprisingly tricky: I want to trim all whitespace, except the space character: ‘ ‘. In Java, the RegEx I have tried is: [s-[ ]], but this one also strips out ‘ ‘. UPDATE: Here is the particular string that I am attempting to strip spaces
Remove all empty lines
I thought that wasn’t that hard to do, but I want to remove all empty lines (or lines just containing blanks and tabs in Java) with String.replaceAll. My regex looks like this: But it doesn’t work. I looked around, but only found regexes for removing empty lines without blanks or tabs. Answer Try this: Note that the regex [ |t]
Search for a word in a String
If I am looking for a particular word inside a string, for example, in the string “how are you” I am looking for “are”. Would a regular indexOf() work faster and better or a Regex match() Which of the two methods above is a better way of looking for a string inside another string? Or is there a much better
Parsing command-line arguments from a STRING in Clojure
I’m in a situation where I need to parse arguments from a string in the same way that they would be parsed if provided on the command-line to a Java/Clojure application. For example, I need to turn “foo “bar baz” ‘fooy barish’ foo” into (“foo” “bar baz” “fooy barish” “foo”). I’m curious if there is a way to use the