All Questions
23,523
questions
1
vote
0
answers
42
views
Regex that allow alphanumerics, spaces, dots, hyphens, but not an empty string
I have this REGEX in Java that alllow simple short sentences with alphanumerics, dots, hyphens and white spaces:
Pattern MAX_LENGTH_30_NO_SPECIAL_CHAR_ = Pattern.compile("[A-Za-z0-9\\s\\-.]{1,30}&...
-4
votes
1
answer
67
views
Java String split by empty lines including empty lines at the end [closed]
I have seen many questions and answers online, but it seems that I cannot find the case that I have.
String s = "a\nb\n\nc\n\n\n\n";
String[] split = s.split("\\R");
//is the same ...
2
votes
1
answer
61
views
Sonarlint refactor this repetition that can lead to stack overflow regex expression [duplicate]
I have to write a java regular expression to find if a string has at least 6 digits in it. The digits may be separated by space, hyphen or other characters.
The java pattern that I wrote "^(?=.(?:...
0
votes
2
answers
79
views
Regex Pattern to Mask Field with Commas in Java [closed]
I am working on a Java application that processes strings. I need to mask the content of a specific field. The challenge I'm facing is that this field sometimes contains commas, which interferes with ...
-1
votes
1
answer
69
views
How to use a regex group and backreference to verify file contents
I have a file with timestamps and want to verify the contents. Two lines within the file should have the same timestamp value (but the value changes from run to run). I want to verify that whatever ...
0
votes
4
answers
74
views
Java Regular Expression not working for this special use case
The following is my code:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String args[]) {
String pageText = "Other ...
-1
votes
0
answers
38
views
Java Regex doesn't find matches as expected [duplicate]
So I'm trying to get the coordinates from an GPX file via regex.
The file:
<?xml version="1.0" encoding="UTF-8"?>
<gpx
version="1.1"
creator="Runkeeper -...
0
votes
1
answer
67
views
Regex to find methods that have an 'inner' method
I'm working on some upkeep for a monolithic java codebase, where it was discovered that some of the @GET methods will actually start a write session, and should thus actually be @POST methods. I wrote ...
1
vote
1
answer
47
views
String matches method - forward slash not working
I am trying to match file paths of the following pattern:
/Users/someuser/folder/folder/config/server1/overlay.properties
I am using the following code to walk through the files in a path and match ...
0
votes
1
answer
40
views
How to match the content in parentheses using Java
The following is my code, based on jdk17. I want to match the content in the parentheses. I have no problem matching it using the online platform, but I can't match it using Java code.
package com....
3
votes
2
answers
75
views
Need regex to match word bounded by / or end of string
I need a regular expression to parse out the companyid and branchid in a url.
The issue is that the branchid may occur at the end of the string or it may occur in the middle of the string. it will ...
0
votes
3
answers
79
views
Java regular expression for multiple matchers
I'm trying to build a regular expression to return initial value and then all key value pairs.
Text is
abcd{123}hello world{456}asd * ~ . , 1243214 aadasd{678}asd aaasddd
Expected output is
...
0
votes
1
answer
69
views
Regular expression - same group later
(This is in java) I am trying to match this string
"aaaBaaa"
using this java regex
(a+)B\1
The \1 is supposed to mean first group (the a+ portion of the pattern)
But this is wrong and ...
-2
votes
3
answers
70
views
regex: replace everything but the matching pattern (java)
I have a text line matching this pattern \d{2}\s?[a-zA-Z]\s?\d{2,5} zero to many times.
That pattern will match char sequences which can be described as following: two digits, followed by one letter ...
2
votes
1
answer
59
views
Match text, also match text when enclosed with listed neighbours
I am working on multi-replacement tool and need to replace name of OBJECT_TYPE to different variants.
I have several instances of such name and need to replace it only when relevant, so the rule is to ...