Regex pattern to replace characters [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 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]*$

Related

Regex Logic - replace commas between two numbers with dots [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 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

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 to search for everything before a string, and after [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 like to search for everything before the string http://thepaperwall.com/wallpapers/ but not including that string.
I would also like to search for everything after .jpg but not including .jpg.
So my final string should look like this:
http://thepaperwall.com/wallpapers/cityscape/small/small_642331afcd78d0840485bb352d99b289b50e8467.jpg
How can I do this?
You can use look-behind and look-ahead to get a string position between 2 other strings:
(?<=http://thepaperwall.com/wallpapers/).*(?=\.jpg)
You need a non-capturing group:
(.*)(?:http:\/\/thepaperwall\.com\/wallpapers\/.*\.jpg)(.*)
Live demo

i want to parse a string between two -'s by using regexp [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 8 years ago.
Improve this question
i want to parse the values between -. but for some data like 1st url contains -- so in that case i need to get the gap only and the next one i am able to get **camry** successfully by using *(site_data,'[^-]+',1,2)*. but i want to handle the gap as well.
U=Google--undefined|http://www.google.com/urlsa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=2&ved=0CFMQFjAB&url=http://www.toyota.com/tundra/features.html&ei=-zwQUvOyGIXu2QWC7oGgBg&usg=AFQjCNFQKGcr2dbDeC-0zagtYdKFEfXXzQ&bvm=bv.50768961,d.aWc
U=Bing-camry-undefined|http://www.bing.com/searchq=camry&pc=MOZI&form=MOZSBR
Please help on this.
You can extract the string along with the hyphens, and then trim the hyphens.
trim('-' from regexp_substr(site_data,'-[^-]*-'))
Alternatively, you can also use regexp_replace function.
regexp_replace(site_data,'(-([^-]*)-)|(.)','\2')

Another RegEx to match wanted result [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 8 years ago.
Improve this question
I'm having another issue where I want to extract values from a string. Please take a look.
string anotherTest = "Hello World [A12345 **(05,00,45)**] - [518.6Z] [51.5]"
I would like the result to return "A12345" "518.6Z" "51.5".
What I highlighted in bold is what I'm having issue with.
I'm using c# and I've tried [(\D?\d+.?\d+\D?)] ... which is fine if I don't have what's in parentheses.
You need to extract the first word from a [ ... ] substring. Use groups:
.*?(\[([^\[\] ]+).*?\])*
Then extract second group from all the captures (depending on your langauge)