Why regex extract return wrong value in scala [closed]

val pattern = “[A-Z]{2,3}[0-9]{4}”.r val extractedData = pattern.findFirstIn(“find ABCD1234”) I have the above code to look for valid data. Input: find DTD0001 Expected Output: …

How to split a string into two considering end of the string with numbers (which is inside the squre brackets)

I need to split strings into two with a given separator using regex. Sample Strings and expected output as below testnames[3] ===> testnames,3 3alpha[0] ====> 3alpha, 0 beta[4]value[2] ===> …

How to replace occurance of numbers with single value?

I have below code String str = “/admin/3138/misc”; boolean isNumbers = str.chars().anyMatch(Character::isDigit); System.out.println(isNumbers); if (isNumbers) { str = str.replaceAll(&…

Why does this regex fails to check accurately?

I have the following regex method which does the matches in 3 stages for a given string. But for some reason the Regex fails to check some of the things. As per whatever knowledge I have gained by …

Make RegEx optional groups either BOTH be present and match, or if ONE is missing not match/fail (java)

I have a RegEx pattern I am using and it works (mostly), but there is one bug. I have 3 separate groups to capture the values, serverXXX (group 1), -Site (group 2, optional) and YY (group 3, optional)….

Cant find pattern with Scanner in Java 8

I’m working with Java 8 on eclipse and trying to use regex to detect strings in a file, but I’m not detecting anything. I’ve tested the regex on its own and it successfully match’s strings in the file …

Java Pattern and Matcher no result

i’m writing this Java program for fun and i’m trying to get groups of substring with a regex. My string is read from a file and it’s something like: tJohn</…

Find passwords values in JSON objects using Regex

I have a big JSON object which contains a lot of different JSON, most of them have the structure below (key: sometext-v1.password, and value: password for example: “apps”:[ “…

How could I select a range of characters up until a third / is present and select all if there is no third / using regular expression

I need to select a range within a string up until the third / is present. I currently have ^([^/]*/[^/]*/[^/]*/ but this will only work when there is more than 3 / in the string. Ideally I’d …

How can I get a special part in a string in Java? [closed]

I have to read commands from a file I have and take necessary actions according to each command. I was able to find out the process of reading from the file and what the command is, but I am having …