Jump to content

StringRegExpReplace does not working properly - (Moved)


Recommended Posts

$t = '... 1-347-318-9643  1-347-318-9647  1-347-318-9648  1-347-318-9650  1-347-318-9651  1-347-318-9652  1-347-318-9653  1-347-318-9655  1-347-318- ...'

$pattern = '347.*?318.*?9655'
$tmp = StringRegExpReplace($t, $pattern, "|||", 1)
ConsoleWrite($tmp & @CRLF)

However i got this output:

... 1-|||  1-347-318- ...

Why i got only that, where is the other string, i thought the output should be this:

... 1-347-318-9643  1-347-318-9647  1-347-318-9648  1-347-318-9650  1-347-318-9651  1-347-318-9652  1-347-318-9653  1-|||  1-347-318- ...

Link to comment
Share on other sites

you need to define your pattern better.  You are replacing from the first time it finds 347 (characters 7-9 in your string) then as many chars as necessary until 318 (chars 11-13) then capture as many chars as necessary until 9655 (chars 123-127), so in this case is most of your string.  If there can ever only be a single character to separate you may not need * or ? as it gets greedy quick.

$t = '... 1-347-318-9643  1-347-318-9647  1-347-318-9648  1-347-318-9650  1-347-318-9651  1-347-318-9652  1-347-318-9653  1-347-318-9655  1-347-318- ...'

$pattern = '347.318.9655'
$tmp = StringRegExpReplace($t, $pattern, "|||", 1)
ConsoleWrite($tmp & @CRLF)

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

On 7/7/2018 at 10:47 PM, iamtheky said:

you need to define your pattern better.  You are replacing from the first time it finds 347 (characters 7-9 in your string) then as many chars as necessary until 318 (chars 11-13) then capture as many chars as necessary until 9655 (chars 123-127), so in this case is most of your string.  If there can ever only be a single character to separate you may not need * or ? as it gets greedy quick.

$t = '... 1-347-318-9643  1-347-318-9647  1-347-318-9648  1-347-318-9650  1-347-318-9651  1-347-318-9652  1-347-318-9653  1-347-318-9655  1-347-318- ...'

$pattern = '347.318.9655'
$tmp = StringRegExpReplace($t, $pattern, "|||", 1)
ConsoleWrite($tmp & @CRLF)

 

That is great, i was not clear about the pattern. thank you very much.

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

×
×
  • Create New...