Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
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}&...
Rafael A P Nascimento's user avatar
-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 ...
Matjaz's user avatar
  • 484
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 "^(?=.(?:...
gcpd0711's user avatar
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 ...
Amna Zahid's user avatar
-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 ...
jwrey01's user avatar
  • 17
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 ...
mukund's user avatar
  • 2,970
-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 -...
D. Hoven's user avatar
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 ...
user9934848's user avatar
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 ...
James Jithin's user avatar
  • 10.4k
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....
孔乙已's user avatar
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 ...
amadain's user avatar
  • 2,818
-2 votes
0 answers
35 views

Java String split by point or space [duplicate]

The task is to split address on parts by point or space. For example: "c.Town" should be split to "c." and "Town" And "c Town" to "c" and "Town&...
Jelly's user avatar
  • 1,192
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 ...
wasanka wickramasinghe's user avatar
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 ...
Lazaruss's user avatar
  • 1,209
-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 ...
ibexit's user avatar
  • 3,547

15 30 50 per page
1
2 3 4 5
1569