Jump to content
Sign in to follow this  
EvAsion

Another StringRegExpReplace query.

Recommended Posts

EvAsion

If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1'

and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side?

something like

$string = "He232"
$replace = StringRegExpReplace($string, "\d?\w+","\0,")

Edit: See bottom post

Edited by EvAsion

Share this post


Link to post
Share on other sites
SmOke_N

If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1'

and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side?

something like

$string = "He232"
$replace = StringRegExpReplace($string, "\d?\w+","\0,")oÝ÷ Ûú®¢×«b²+m«r¢æ«{
+)à¢{h«Þ¶Þ²¥iº+j×¢»ayø«²Úު笶Z(«@e©Ýk=§v·ª¹ë-jëh×6$string = "He232"
$replace = StringRegExpReplace($string, "(?!:\w+)\d+",",\0")
MsgBox(0, 0, $replace)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
EvAsion

Thanks that works brilliantly.

Well its basically for some percentage composition chemical analysis thing i am trying to implement in my periodic table. I retrieve the atomic mass of an element from a database and then multiply it by the number following. The script fails if there is no number following, so i want to make sure there is always a number between each elements, so 1 if none is specified.

Something along the lines of this:

$string = "HeHC"
$replace = StringRegExpReplace($string, "([A-Z][a-z])[A-Z]","\0 1")
msgbox(0,"",$replace)
Edited by EvAsion

Share this post


Link to post
Share on other sites
SmOke_N

Bump.

What are you bumping? I gave you your answers.

(You also may want to hold off on editing posts hour(s) after making them, some of us don't go back and read the post several times.)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Sheri

If i have 2 capital letters next to each other, or a noncapital next to a capital, how can i put a 1 between them(or if i have a capital letter then white space or nothing, put a 1 after the capital letter)? So 'HeHP' becomes 'He1H1P1'

and also, how can i put a , in a string like 'He232' between the end of the letters and the start of the numbers (becoming 'He,232'), regardless of how many letters/numbers there are on each side?

something like

$string = "He232"
$replace = StringRegExpReplace($string, "\d?\w+","\0,")oÝ÷ ØGbµ'nm¢jh²ßêº^N¼­ëjëh×6$string = "He232"
$replace = StringRegExpReplace($string, "(?i)([A-Z]+)(\d+)","$1,$2")
msgbox(0,"", $string & ":" & $replace)
$string = "HeHP"
$replace = StringRegExpReplace($string, "(?-i)(?<=[a-zA-Z])[A-Z]|\z","@$0")
$replace = StringRegExpReplace($replace, "@", "1")
msgbox(0,"", $string & ":" & $replace)

Hopefully your input doesn't have any @ characters, if it does you will need to choose another proxy character for the 2nd and third replacements. I couldn't find any documentation for AutoIt's regex replacement string and nothing I tried using a "1" seemed to work.

Share this post


Link to post
Share on other sites
EvAsion

I am amazed sheri, thankyou so much.

SmOke_N I very much appreciate your help aswell, I apologise for bumping. The reason i edited my post so late was because i felt that i should add an example of what I had attempted. Showing that I tried something seems to be good around here, and I did not want to sound like the type that just sais 'tell me how to do this and that', which is the general vibe of this thread already.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.