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 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
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
Right now I have this regex:
/regular(\[[a-z]*\])* expression/i
which correctly matches this string:
Regular[AECC][XVK] Expression
but fails to match these:
R[AECC]egular [XVK]Expression
R[ABC]egular Expression
Regular[xx] Expressio[]n
How can I match all of the above with a single regex?
/
r (?:\[[a-z]*\])?
e (?:\[[a-z]*\])?
g (?:\[[a-z]*\])?
...
i (?:\[[a-z]*\])?
o (?:\[[a-z]*\])?
n
/ix
or
my $pat = join '(?:\\[[a-z]*\\])?', map quotemeta, split //, 'regular expression';
my $re = qr/$pat/i;
/$re/
or
s/\[[a-z]*\]//ig;
/regular expression/i
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]