[Pro] Multiple - Regular Expressions & Modifiers

Hi Everyone
Does anyone have a reference for regular expressions and modifiers in freeway.
What I am trying to do is change 2 parts of the freeway output within a div to 2 others.

eg.
so for example the text says this:

hello and goodbye

so normally I would write this:

  MyText = MyText.replace(/hello/g,'max says hello');

and that would change the above text to:

max says hello and goodbye

But if I also want to be able to replace goodbye at the same time to say

rachel says goodbye

How would I add that second modifier… Does any one have a reference on how thats done within freeway ?
All the examples I have only show 1 find and replace rather than multiples with different changes

all the best Max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I seriously recommend the OReilly title “Mastering Regular
Expressions”. Regexen are the Swiss Army knife of software, and this
book will tell you where they hid the tweezers. Plus, there’s quite a
nice owl on the cover.

As far as I know, there isn’t any way within a single regex to find
all instances of ‘hello’, replace them with ‘max says hello’ and also
find any instance of ‘goodbye’ and replace it with ‘rachel says
goodbye’ within the same regex IF your other requirement is that hello
and goodbye might be in a different order. If you always know that
hello will come before goodbye, then it is possible in a very limited
way to capture the words hello and goodbye along with all of the text
between them. But that’s a very brittle solution, since it depends on
knowing the order of elements within the input text, and a good regex
is completely agnostic that way, so it’s harder to break. I would
recommend splitting the task into two separate expressions, and
chaining them:

input.replace(/hello/g,'Max says hello').
	replace(/goodbye/,'Rachel says goodbye');

If you wanted to grab hello, goodbye, and whatever is between them,
you could do this:

input.replace(/(hello)([sS]+?)(goodbye)/igm,"Max says$1$2Rachel says 

$3");

This will grab any pair where hello is followed by something (not
goodbye) followed by goodbye, and perform the substitution, using the
matched captures ($1, $2, $3) as part of the replacement. It will do
so across multiple lines of input (the m flag, it will match Hello and
hello (the i flag), and it will match as many pairs as it finds (the g
flag). What it will not do is properly deal with goodbye and hello in
that order. It will break very easily. That’s why the arguably
“stupider” solution of chaining two simpler expressions will win in
the end.

Walter

On Jun 12, 2011, at 8:36 AM, max wrote:

Hi Everyone
Does anyone have a reference for regular expressions and modifiers
in freeway.
What I am trying to do is change 2 parts of the freeway output
within a div to 2 others.

eg.
so for example the text says this:

hello and goodbye

so normally I would write this:

 MyText = MyText.replace(/hello/g,'max says hello');

and that would change the above text to:

max says hello and goodbye

But if I also want to be able to replace goodbye at the same time to
say

rachel says goodbye

How would I add that second modifier… Does any one have a
reference on how thats done within freeway ?
All the examples I have only show 1 find and replace rather than
multiples with different changes

all the best Max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Hi Walter the split expression works for me
thanks for the reference recommendation too…
all the best max


actionsdev mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options