Regex replacements (\1, \2) not matching

Kaveh Bazargan kaveh at rivervalleytechnologies.com
Sun Nov 11 10:26:13 EST 2018


Thank you both for your comments. My jaw dropped that I had not noticed
that before!! I need to do a lot of text manipulation, so hopefully I can
do that with LiveCode's friendly and powerful text chunk features.

On Sun, 11 Nov 2018 at 14:22, Sean Cole (Pi) via use-livecode <
use-livecode at lists.runrev.com> wrote:

> Hey Kaveh,
>
> 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"
> verbatim.
>
> 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.
>
> Sean
>
>
> 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
> > Director
> > River Valley Technologies <http://rivervalleytechnologies.com/> •
> Twitter
> > <https://twitter.com/kaveh1000> • LinkedIn
> > <https://www.linkedin.com/in/bazargankaveh/>
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> > subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode



-- 
Kaveh Bazargan
Director
River Valley Technologies <http://rivervalleytechnologies.com/> • Twitter
<https://twitter.com/kaveh1000> • LinkedIn
<https://www.linkedin.com/in/bazargankaveh/>



More information about the use-livecode mailing list