Regex replacements (\1, \2) not matching
Sean Cole (Pi)
sean at pidigital.co.uk
Sun Nov 11 09:21:48 EST 2018
To break down your request you are searching if the string "one two"
matches the pattern "(.+) (.+)" which it does as there are two word with a
space between that can have at least 2 characters per word (. = any
character, + = and extra character of that type, in this case 'any'). As it
does match that pattern, replaceText simply swaps out the "one two" for
exactly the string you have asked it to replace it with, namely "\2 \1"
The replacement string cannot itself be a regex pattern which is what I
think you are trying to do here. The regEx part in the middle of the
function is just a pattern to match to and not a method to reorganise the
content of the search string, which is unfortunate. You would need a
slightly longer script to achieve this. A repeat loop using 'put "2,1" into
tSortOrder'; put trueword (item x of tSortOrder) of tOldString into word x
of tNewString' would do what you want in simple terms.
On Sun, 11 Nov 2018 at 09:40, Kaveh Bazargan via use-livecode <
use-livecode at lists.runrev.com> wrote:
> What am I missing? I put in message box:
> put replacetext("one two", "(.+) (.+)", "\2 \1")
> I get result:
> "\2 \1"
> rather than:
> "two one"
> Kaveh Bazargan
> River Valley Technologies <http://rivervalleytechnologies.com/> • Twitter
> <https://twitter.com/kaveh1000> • LinkedIn
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
More information about the Use-livecode