The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

why is regex ^[0-9][0-9][0-9][0-9] failing when checking '1446'. works in java regex checker

rob.zimmelman
April 7, 2021

using regex validator against a field containing a 4 digit number (hour and minute of day), number is '1446', using  ^[0-9][0-9][0-9][0-9] and it is failing.  when i try the same in https://www.freeformatter.com/java-regex-tester.html#ad-output or in python 're' module, e.g. it works.

2 answers

2 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Thomas Deiler
Community Champion
April 23, 2021

Dear @rob.zimmelman ,

I have no answer for your question, but dose this RegEx work?

[0-2][0-9][0-5][0-9]

I have proved this RegEx with following Java code:

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("[0-2][0-9][0-5][0-9]", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher("1446");
boolean matchFound = matcher.find();
if(matchFound) {
System.out.println("Match found");
} else {
System.out.println("Match not found");
}
}
}

So long

Thomas

rob.zimmelman
April 23, 2021

 this is working doing validation on the 'summary' field.

0 votes
Answer accepted
rob.zimmelman
June 9, 2021

accomplished what i needed by making a sql query for GETDATE() which worked in the query comparison where the string comparison i was doing in regex with the string returned from an endpoint that returned 'hhmm' wasn't working

TAGS
AUG Leaders

Atlassian Community Events