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 5 months ago.
Improve this question
I have a String pattern: "hh:mm:ss dd:MM:yyyy to hh:mm:ss dd:MM:yyyy" and I want to extract date String from it.
Example:
S = "00:00:00 19/08/2022 to 23:59:59 19/08/2022"
Split into S1 = "00:00:00 19/08/2022" and S2 = "23:59:59 19/08/2022".
I'm trying to use String.split function but can't figure out the regex yet. Can somebody help?
I'm using Java 8.
Just split on \s+to\s+:
String pattern = "00:00:00 19/08/2022 to 23:59:59 19/08/2022";
String[] parts = pattern.split("\\s+to\\s+");
System.out.println(Arrays.toString(parts));
This prints:
[00:00:00 19/08/2022, 23:59:59 19/08/2022]
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 3 years ago.
Improve this question
So I have a CSV file with some anomaly for eg
2019-07-25 00:00:00,1014488,2019-07-25 12:24:12,112629,Amy,Flutmus,84004,GM,0001,2.99,312,FFO & CS PLATE ||22,10999,90027,90062||Sand w/ Options,1,0,0.2,18.85,0,1
i want to replace , between these characters || ||.
So I'm expecting
2019-07-25 00:00:00,1014488,2019-07-25 12:24:12,112629,Amy,Flutmus,84004,GM,0001,2.99,312,FFO & CS PLATE ,22,*10999*90027*90062,Sand w/ Options,1,0,0.2,18.85,0,1
You could use re.sub to capture all your strings between || and then replacing the ,s with *s:
import re
value = "2019-07-25 00:00:00,1014488,2019-07-25 12:24:12,112629,Amy,Flutmus,84004,GM,0001,2.99,312,FFO & CS PLATE ||22,10999,90027,90062||Sand w/ Options,1,0,0.2,18.85,0,1"
pattern = re.compile(r'\|\|(.+)\|\|')
cleaned_value = pattern.sub(lambda match: match.group().replace(",", "*"), value)
print(cleaned_value.replace(r'||', ','))
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
For example
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
extract lines between 1cn8 to 1cn12
like this i have hundreds of line, want to extract any range by giving the input.
$ cat test | grep '[$0-9]'
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
these are node names, want to extract node names within the node range. lines starting from1cn8 till 1cn12
You can try something like that:
[[:alnum:]]{3}([8-9]|1[0-2])
Short explanation:
[[:alnum:]]{3}: matchs with any letter (upper or lower case) and digits, over 3 times;
([8-9]|1[0-2]): matchs with 8 and 9 [8-9] OR |, the number one with 0, 1 or 2, 1[0-2]
$ cat test
1cn1
1cn2
1cn3
1cn4
1cn5
1cn6
1cn7
1cn8
1cn9
1cn10
1cn11
1cn12
$ egrep '[[:alnum:]]{3}([8-9]|1[0-2])' test
1cn8
1cn9
1cn10
1cn11
1cn12
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 7 years ago.
Improve this question
Example: DATA500 replaced with DATA[500]
This should work. It replaces groups of one or more digits, the "\d+" part, with the captured string surrounded by [], the "[$1]" part.
$a = "bob123bob123";
$a =~ s/(\d+)/[$1]/g;
print "$a";
# bob[123]bob[123]
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 9 years ago.
Improve this question
I need write a regular expression which accept a-z , A-Z,0-9 and -(dash) as a special character .
valid inputs : 1 : mohit-kumar-gulati
2 : mohit1-kumar1-gulati
3 : mohit1-kumar1-gulati
4 : 234-545-345
Invalid inputs : 1 : mohit#-kumar-gulati
2 : mohit1-kumar1$-gulati
3 : ###%^-kumar1-gulati
4 : %^-::-''::
5 : *(*mohit
Use this one:
[A-Za-z]*-?[A-Za-z]*
If it is C# you should use a regex like this:
Regex regex = new Regex(#"^[-\w]+$");
Good luck with your quest.