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

Related

Split string by word contain space in Java [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 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]

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>

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

Ignoring bracketed sections in a regex match [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
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

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]