Split string by word contain space in Java [closed] - regex

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]

Related

extract string have dot using regex substr oracle [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 8 months ago.
Improve this question
Input string:
(select FRL_ATTRIBUTE_DESCRIPTION from FRL_ATTRIBUTES WHERE FRL_ATTRIBUTE_LEVEL =9 AND FRL_Lines_PL.FRL_ATTRIBUTE_09 = FRL_ATTRIBUTE)
Ouput :
FRL_Lines_PL.FRL_ATTRIBUTE_09
i need to extract FRL_Lines_PL.FRL_ATTRIBUTE_09 alias name string using regex_substr
You said you want to extract a string that contains a dot and provided example. OK, if that's exactly what you have & need, then
SQL> with test (col) as
2 (select '(select FRL_ATTRIBUTE_DESCRIPTION from FRL_ATTRIBUTES WHERE FRL_ATTRIBUTE_LEVEL =9 AND FRL_Lines_PL.FRL_ATTRIBUTE_09 = FRL_ATTRIBUTE)' from dual)
3 select regexp_substr(col, '\w+\.\w+') result
4 from test;
RESULT
-----------------------------
FRL_Lines_PL.FRL_ATTRIBUTE_09
SQL>

How to use regular expression in Hive to extract the second integer? [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 3 years ago.
Improve this question
Data:
BUY 2 FOR 5(STORES)
BUY 2 FOR 10(STORES)
What I tried:
regexp_extract(DATA, '.*? (\\d+) .*$', 2)
Desired result:
5
10
Like this:
regexp_extract(DATA, '^[^0-9]+?\\d+[^0-9]+?(\\d+)', 1);
or
regexp_extract(DATA, '^\\D+?\\d+\\D+?(\\d+)', 1);
Regex means: one or more Non-digits at the beginning, one of more digits, one or more non-digits, and finally the capturing group of digits, you need to extract the group number one.
One more solution is to split string by non-didits and take 2nd element:
select split(DATA, '[^0-9]+')[2];
Or even simpler:
select split(DATA, '\\D+')[2]; --\\D+ means one or more non-digits

Find and Replace , between 2 characters [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 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'||', ','))

Regex to use in HTML source [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
I need a regex to extract the number 330 on ...163&angleKreludor=330&viewID=.... This number vary from day to day...it could be an Integer with up to 3 digits, but it can be a double number like 127.57 with 2 decimal places ... so I would need to capture anything between angleKreludor= and &viewID.... Here is the complete HTML:
var swf = new SWFObject('http://images.lulaser.com/shenkuu/lunar/shenkuu_calendar_v1.swf?angleNeopia=163&angleKreludor=330&viewID=2&lang=pt', 'flash_36175654223', '550', '500', '6', '#FFFFFF');
swf.addParam('quality', 'high');
swf.addParam('scale', 'exactfit');
swf.addParam('menu', 'false');
swf.addParam('allowScriptAccess', 'always');
swf.addParam('swLiveConnect', 'true');
swf.addParam('bgcolor', 'white');
swf.write();
P.S: This is needed to use in Javascript code in Selenium IDE ... I tried in the past and Selenium IDE does not accept look-aheads nor look-behinds
You can search for digits with positive look-behind for the angleKreludor= key
(?<=angleKreludor=)(\d+)
DEMO
For JavaScript use non-captuinrg group
(?:angleKreludor=)(\d+)
var s = 'http://images.lulaser.com/shenkuu/lunar/shenkuu_calendar_v1.swf?angleNeopia=163&angleKreludor=330&viewID=2&lang=pt';
var nr = s.match(/(?:angleKreludor=)(\d+)/);
console.log(nr[1]);
DEMO

I have a string in perl, how do I replace it with the same string but with [ ] around only the numbers? [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 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]