Regex Logic - replace commas between two numbers with dots [closed] - regex

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 1 year ago.
Improve this question
Hello there can i have an hint about how should i write the regex code to search for the commas (,) in those values between the |'...'| pattern? i need to find the commas and replace with dots(.) , if there's a comma in there of course.
|'2,3'|;|'5,6'|;|'2,1'|;|'3'|;|'6,5'|;|'9'|;|'7'|;|'4,4'|;|'4'|;|'1,1'|
expected result:
|'2.3'|;|'5.6'|;|'2.1'|;|'3'|;|'6.5'|;|'9'|;|'7'|;|'4.4'|;|'4'|;|'1,1'|
the pattern can be also what i will write below depending on some input parameters that i am going to receive in my method:
|'2,3'|,|'5,6'|,|'2,1'|,|'3'|,|'6,5'|,|'9'|,|'7'|,|'4,4'|,|'4'|,|'1,1'|
expected result:
|'2.3'|,|'5.6'|,|'2.1'|,|'3'|,|'6.5'|,|'9'|,|'7'|,|'4.4'|,|'4'|,|'1.1'|
this why i need a pattern for this because i don't know if i will receive the string with (;) or (,) separating the values
thanks so much

Regex Pattern
Here is the pattern that you can use to search for the commas , between two numbers
(?<=[0-9]),(?=[0-9])
Regex Demo

Related

Cannot use ^(hat) in parentheses regular expression [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 2 days ago.
Improve this question
I tried to capture file extension: get .m3u8 if my filename is ABC.m3u8 for example.
The regular expression I use:
\w+(^\.[A-Za-z0-9]+)
I cannot get the result as my expected if I don't remove hat(^) character. Please tell me why, thanks.
There are two issues with \w+(^\.[A-Za-z0-9]+) :
^ would match the beginning of the string
not anchoring it at the end would give false captures, such as .foo for abc.foo.mp3
Here is the corrected regex:
^[\w+\.]+(\.[A-Za-z0-9]+)$
Or simply:
(\.[A-Za-z0-9]+)$
Learn more about regex: https://twiki.org/cgi-bin/view/Codev/TWikiPresentation2018x10x14Regex
^means match the beginning of a line, rather than beginning with ., so adding ^ will not match.

How to remove comma at end of extracted value? [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 2 years ago.
Improve this question
I am having the following String
{'Sample': '#it{tq}', 'Yield': 0.011063753491221462, 'Error': 0}
and I would like to extract the value from 'Sample', that means '#it{tq}'. I tried that using a regular expression: 'Sample':(\s*.+?\s)
but its giving me: '#it{tq}', including that comma at the end. Does anyone know how to erase the comma at the end?
this regular expression should do the job.
regex: 'Sample':\s*('[^']*')
https://regex101.com/r/DL5Ltq/2
how about using this:
'Sample': '(.*?)',
beware that the regex in the accepted answer cannot process the case having single quote escape text inside the capture group like this: {'Sample': '#it'{tq}'}.
If you use (.*?), it greedily process any single character inside two single quote.

Regex pattern to replace characters [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 2 years ago.
Improve this question
The program contains text of this type:
A B Ccccc
A Ccccc
ACcccc
ABCcccc
I need only such text to remain:
Ccccc
I wrote a replacement function, but I just can’t pick up a pattern
How to make such a pattern?
No need for regex, nor VBA. It seems you simply are looking for the position of the last upper-case letter and then to extract from there:
Formula in B1 (with Excel O365):
=MID(A1,MAX(SEQUENCE(LEN(A1))*(EXACT(UPPER(MID(A1,SEQUENCE(LEN(A1)),1)),MID(A1,SEQUENCE(LEN(A1)),1)))),LEN(A1))
If you don't have Excel O365:
=MID(A1,MAX(ROW(A1:INDEX(A:A,LEN(A1)))*(EXACT(UPPER(MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1)),MID(A1,ROW(A1:INDEX(A:A,LEN(A1))),1)))),LEN(A1))
You probably need to enter as array through: CtrlShiftEnter
If you must go through VBA and regex then a pattern like:
[A-Z][^A-Z]*$

how to check in python, that a string contains only alphabets and hypen [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 years ago.
Improve this question
I am trying to filter medical words from general english words.
but most of the drugs name contains hypen in it.
pls suggest how to check in python, that a string contains only alphabets and hypen.
for example : anti-allergic
Simplest way to check string is as below, remove '-' from string and check if remaining characters are all alphabets.
test_str = 'anti-allergic'
if test_str.replace('-','').isalpha():
print('Valid string')
This can be accomplished by using regular expressions (https://docs.python.org/3/library/re.html), where a (very quick and dirty) regex could ask for all letters, a to z (and A to Z), that has a hyphen in it.
([a-zA-Z]+[-].+)
Would match the following:
suoad
ADDADA
waeewrw
omaeqweSADADSwu
iraaief
anti-allergic
ANTI-ALLERGIC
testtesttest
You can test this out yourself using https://pythex.org/.

Regex of changing numbers [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 9 years ago.
Improve this question
I would use regex to select one changing number
For example in the following example I would select 12090343 that I could change
I use:
preg_match (/(?<=Dossier.N..)(.*)(?=-)/)
It works but it's not so clean I think because the number of spaces could change and so it will not detect the number any more
Dossier N° 11110144-001 Pvt du : 03/09/2013 à 7:16
It looks fine, but you could slightly clean it up by .not grouping the number and making it match digits:
(?<=Dossier.{0,3}N.{0,3})\d+(?=-)
Most regex engines can't handle look behinds of arbitrary length, so rather than using the simpler (but unbounded) expression \s*, you must use a limited length expression like \s{0,3} to allow "some" whitespace.
You can try the following expression:
/Dossier[^0-9]*\K([0-9]*)(?=-)/
Regex101 Demo