Jump to content

help with StringRegExpReplace plz


jennico
 Share

Recommended Posts

i want to check strings and insert a space between every dot and a following digit.

for example:

no.1 => no. 1

127.168.2.1 => 127. 168. 2. 1

fed.res.6789 => fed.res. 6789

i think i could use something that's called "back-reference" in the helpfile, but there is no further explanation.

The text to replace the regular expression matching text with. To insert matched group text, \0 - \9 (or $0 - $9) can be used as back-references.

what i have (not working) is:

$x=""
While 1
    $x=InputBox("",$x)
    If $x="" Then Exit
    $x=StringRegExpReplace($x,"\.\d",". \0")
WEnd

pattern is okay, but replace not.

thx for your help

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

$Str = StringRegExpReplace($sStr, "(\.)(\d)", "\1 \2")

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

thx geosoft, that's it !

so i was right with the back-reference ?

\1 means first part in the matchstring

\2 second part

\0 the entire matchstring ?

right ?

thx.

j.

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

thx geosoft, that's it !

so i was right with the back-reference ?

\1 means first part in the matchstring

\2 second part

right ?

thx.

j.

Thats right. You could also use "$1 $2"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

and $0 (\0) is the entire string ?

edit: btw

the helpfile for stringregexp states:

( ... ) Group. The elements in the group are treated in order and can be repeated together. e.g. (ab)+ will match "ab" or "abab", but not "aba". A group will also store the text matched for use in back-references

didn't see that before.

thx

Edited by jennico
Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

and $0 (\0) is the entire string ?

edit: btw

the helpfile for stringregexp states:

( ... ) Group. The elements in the group are treated in order and can be repeated together. e.g. (ab)+ will match "ab" or "abab", but not "aba". A group will also store the text matched for use in back-references

didn't see that before.

thx

\0 or $0 is the entire string so it won't work as a replacement with what you are looking for. You would be replacing the entire string with the entire string so 127.0.0.1 would still = 127.0.0.1

What I did was get group 1 which is the first dot that is followed by a digit (\.), notice it has to be escaped.

Then I got group 2 which is the first digit following the dot (\d)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

You can easily test them with this tool

Regular expression tester.

It's not perfect but it is very good.

Also a couple of links for RegExp in general.

http://www.regular-expressions.info/tutorial.html

http://msdn.microsoft.com/en-us/library/hs600312.aspx

The last 2 links are just for general reference. One deals with the dot net regexp engine and the other is primarily for the JGSoft regexp engine however someplace in that mess is a table that gives comparisons between the various engines.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...