This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 6 years ago.
How would I write a Java regular expression that matches everything except the following string?
abc123DEF#domain.com
(?!abc123DEF#domain.com) doesn't work.
Just a simple change of your regex:
(?!abc123DEF#domain.com).*
it works.
Related
This question already has answers here:
Difference between matches() and find() in Java Regex
(5 answers)
Closed 4 years ago.
i have this regex which i want to check if string do contain this structure
none of the strings below match , why?
String s = "T4018.test.12"
or
String s = "T4018.foo.32"
or
String s = "develop"
if(s.matches("T40[0-9][0-9][.][a-zA-Z]+|develop"))
{
//Never matches
}
its do match :
https://regex101.com/r/CSLugb/1
UPDATE
Solved it using Pattern.compile
Maybe you can rewrite the RegEx to "T40\\d{2}\\.\\w+\\.\\d{2}|develop" for matching more exactly. See your 3 test-cases matched in Java
This question already has answers here:
Regexp Java for password validation
(17 answers)
Closed 5 years ago.
string should not be longer than 26 alphanumeric characters
string should not begin with www OR api OR admin
string may contain hyphens
I have this regular expression that works:
^(?!www)(?!admin)(?!api)[a-zA-Z0-9.]{1,26}
Can you help me convert that regex into a java style string regex?
I found the answer by changing my regex to the following:
^(www|api|admin)\w{1,26}$
This question already has answers here:
Java regular expressions and dollar sign
(5 answers)
Closed 6 years ago.
I've got the following code
String valuepairName = "sc_mpl_MAX_AUD_TIME_To_20_Val.$$DATE_TO_LOAD";
boolean result = valuepairName.matches("sc_mpl_MAX_AUD_TIME_To_(20|32|82)_Val.$$DATE_TO_LOAD");
The result evaluates to false, but I cannot see the mistake.
This must be very trivial, hence it's driving me crazy :(
You need to escape each $ individually (or use pattern.quote) ($ is a special character in regex). Use
boolean result = valuepairName.matches("sc_mpl_MAX_AUD_TIME_To_(20|32|82)_Val.\\$\\$DATE_TO_LOAD");
This question already has answers here:
Regular expression to stop at first match
(9 answers)
Closed 7 years ago.
I'm trying to retrieve some parts from a single line html string.
The Regex I wrote is as follows:
String pattern = "rel=\"bookmark\">(.*?)</a></h2>"
The html line is like:
....rel="bookmark">what I need</a></h2>....rel="bookmark">....rel="bookmark">What I also need</a></h2>....
My Regex has two results:
rel="bookmark">what I need</a>
and
rel="bookmark">....rel="bookmark">What I also need</a></h2>
How can I tell it to be less greedy for the second result?
Between tags are the things does not contains < and >
String pattern = "rel=\"bookmark\">[^<>]+</a>";
This question already has answers here:
Regular expression to match a line that doesn't contain a word
(34 answers)
Closed 8 years ago.
I m trying regex to get the strings
starting with # and
not ending with a dot(.)
For that i tried the java code(link here) but this does not show any results -
#(\\w+)*(?<!.(.))*$
The string i m trying is -
This is a test\nAnother #pradyut#test ht#html.com\ntest\n#art\n#cool#paintings#collections
This should return
pradyut
test
cool
The result html ending with a .com should not return.
Regards
You can use this regex:
(?<=#)\w+\b(?!\.)
In Java you have to use:
(?<=#)\\w+\\b(?!\\.)
Regex Demo