Looking for regex to find a sequence of characters [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't know a single bit about regex. I want to find certain occurences in my java project using eclipse. The words could be
SEQ_NUM
SEQNUM
SEQNUMBER
SEQ_NUMBER
searching strings based on word "seq" would generate lots of results. What regex should suffice my problem?

These four cases can be combined to the following regex:
SEQ_?NUM(BER)?

SEQ_?NUM(BER)?
SEQ - must exist
_? - '_' can appear 0 or 1 time
NUM - NUM must also exist
(BER)? - 'BER' can appear 0 or 1 time

This should work for you.
SEQ[_NUMBER]+

Related

Java regular expression is validating the date in ddMMMyyy but not validating yyyy-MM-dd [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I want to validate different kinds of strings which are of different format like
10JUN2022, 2Mx1D, 4M, 1D, TEN, ONE|TEN etc.. and I have written regular expression for that '''^([0-9A-WYZa-wyz ]+)([xX|]([0-9A-WYZa-wyz ]+))?$''' and it's working fine but I also need to validate one more string 2022-06-10, but the expression is failing.
When it comes to regex, don't try to get overly clever. Just solve the basic problem. If that takes multiple regex patterns, so be it. It's much easier to maintain and read.
I would use this for the first regex: [0-3]?\d\w{3}(1|2)\d{3}
and this for the second regex: (1|2)\d{3}(-\d{2}){2}
or combine them if you must: ([0-3]?\d\w{3}(1|2)\d{3})|((1|2)\d{3}(-\d{2}){2})

String formatting under a certain character [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm making a textbook indexer and I'm formatting the output file. there are periods between the word and its frequency.
desired textfile output:
word..............25:
word...............3:
word...............2:
I'm trying to get the lines to be aligned to the : but I can't get it under the semicolon if the numbers are more than 1 digit.
Does anybody have any ideas for java string formatting for the desired output?
for reference the biggest word is 23 characters and it's frequency is 1.
Since in the comment, the OP attempted to use String.format(), here is an approach to consider. Rather than trying to get the number to align right with the "%23d", align the word and the count separately.
String.format("%-23s%2d:", getWord(), count);
The %-23d will format the getWord() in 23 spaces, left aligned, then the %2d will right align the "count".
Example output:
Hello...................9:
Goodbye................42:
whatever...............17:
Note I just used the same .replace() approach as the OP for quickness sake.
See this attempt here at ideone.com

Get a Java string of form (num/num), to become two double values [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For example, if I have a string (24/25), how would I go about being left with two double values of 24 and 25. My objective to to eventually, given a set of number of that form, divide each of them, and add to get the average. I'm fairly new to Java and I honestly am so confused as where to even begin. Thank you!
As Andreas said. First you need to take the substring between brackets. Use String.substr
Now split 24/25 to 24 and 25. You can use String.split
Then you can parse them with Double.parse

Extracting specific charaters on different lines in Java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a file "file.txt" in Java. In the file I have the following values:
10 10
3 3 W
MMMMMRM
4 4 R
LRLRLML
I want to read each line and with each character I want to assign them to a variable which I will use for calculation.
Any idea with how I can proceed with?
Thanks
1) You can use a BufferedReader with the readLine() method to read each line.
2) Then you can use split() for each word or toCharArray() for each character.
3) Then assign said character to predefined variables.
It would be helpful if we could see what you've tried so far or if you could give more details on what you are trying to accomplish.

trying to obtain a first name in the path after first back slash [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to display the first folder name from the path.
/mnt/sdcard/Videos/lk.jpeg, I want to display mnt string. in java
/mnt/sdcard/Videos/lk.jpeg--> **mnt**
You can split on / and use [1] element from result array.
You can either use regular expressions or you can use String.split(). Note that the split() result should be checked for live usage (e.g. if it has at least two elements).
String desired = "/mnt/sdcard/foo".split("/")[1];
String str = "/mnt/sdcard/Videos/lk.jpeg";
System.out.println(str.split("/")[1]);
Try this out. This is a poor question. But maybe the asker can be a newbie.

Categories