#Regex for formatting numbers
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
actually, is it even possible to handle something like converting the word "nothing" to 0 within a regex?
matching the word nothing to regex is fairly ez
this regex looks good to me "(^$[\\d+]\\.[\\d+])"
whenever I test it with a random example it gives me an error
can u show me the whole code ?
other parts as well?
y
ok
public class MembershipFileReader {
public static void main(String[] args) throws FileNotFoundException {
String filename;
double revenue;
File file = new File("C:\\Users\\myFile\\exampleinput.txt");
Scanner scan = new Scanner(file);
String regex = "([a-zA-Z-]+) ([a-zA-Z-]+) has ([\\d]*) [vV]isits left and paid ([%.2f%n]+)" +
" and [s]he joined on (\b(?:Jan(\\w*)?|Feb(\\w*)?|Mar(\\w*)?|Apr(\\w*)?" +
"|May|Jun(\\w*)?|Jul(\\w*)?|Aug(\\w*)?|Sep(\\w*)?|Oct(\\w*)?|(Nov|Dec)(\\w*)?)), " +
"(?:\\d|[12]\\d|3[01]) (\\d{4})";
String regexTest = "(^$[\\d+]\\.[\\d+])";
Pattern p = Pattern.compile(regexTest);
Matcher m = p.matcher("33.10");
if(m.matches()){
System.out.println(m.group(0));
} else {
System.out.println("Error");
}
the sample input I need to work with is
Alistair Baker-Smith has 7 visits left and paid $123.21 and he joined on November 22, 2022
well this is just 1 entry
wow I see you know a lot of regex
I don't know to much regex tho, so I can't help.
im debating on switching my methods to just go with .split
public static void main(String[] args) throws FileNotFoundException {
String filename;
double revenue;
File file = new File("C:\\Users\\myFile\\exampleinput.txt");
Scanner scan = new Scanner(file);
String[] arr= scan.split(" ");
int amount = 0;
for (String word: arr){
if (word.equals('$33.00")){
amount=Integer.parseInt(word.substring(word.
}
sysout(amount);
Detected code, here are some useful tools:
public class MembershipFileReader {
public static void main(String[] args) throws FileNotFoundException {
String filename;
double revenue;
File file = new File("C:\\Users\\myFile\\exampleinput.txt");
Scanner scan = new Scanner(file);
String[] arr = scan.split(" ");
int amount = 0;
for (String word : arr) {
if (word.equals('$33.00")) {
amount = Integer.parseInt(word.substring(word.}
sysout(amount);
also dont use scanner to read file. It's a good practice to use the BufferedReader class
so I would apply this if statement for all 5 key info? like first name, last name, revenue, remaining visits, and join date
br.nextLine()
wait I thought u just wanted the price ..
well no that's just one of the 5 info i need
well the name is always the first word of the sentence ; so it's the first index of the array
last name is the second word ; so the second idx of the arr
u can use the regex to match the dates and the revenue
oh
ye
hope this helps, hope u find some1 better
nah it helped a lot, thanks 🙂
your regex for that will not work, you are essentially starting your regex with start line then end line with ^$ and your + quantifier is in the wrong spot, try : (\\$[\\d]+\\.[\\d]+)