Start a new topic

Replace escaped characters in (multiline) addresses?

Hi all,

Currently working on a file that has an address lines field. I.e. all address lines on one field, delimited by the "\n" newline character.

Is there a way (dictionary perhaps?) to escape these newline characters to actual new lines?

Or do I need to dive back into the API to split the text up into multiple fields?

Cheers,
Tom


Assuming you are talking about the string having the literal characters "\n" in them you could make two dictionaries:

Address Line 1
Replacement Value: $1
Match On: (.+)\\n(.+)

Address Line 2
Replacement Value: $2
Match On: (.+)\\n(.+)

Make sure to check the Use Regular Expressions box

$1, $2, etc. references groupings in the expression denoted by the ().

Regular expressions are fun! Here is a resource that I use a lot to figure them out: http://www.regular-expressions.info/refquick.html
Omatic, is there a way to edit my posts after I submit them?

Try it now... (for some reason "Edit" rights were turned off in this forum).

yay!

Editor still doesn't really work in Chrome and now it looks like signatures are missing newlines? They look like this to me:
*** Wayne Pozzar Senior Manager of Development Operations Partners In Health - Boston, MA http://www.pih.org : wpozzar@pih.org

Edit works just fine for me in Chrome, what are you seeing? We just changed sig to allow HTML, perhaps that caused the sig issue?

@Tom, sorry to hijack your thread!  :)

Hi Jeff (and Tom...)

1) Everything gets center aligned
2) I cannot change the font size
3) bulleted lists do not work (numbers or bullets)
4) Spacing gets stripped when I submit (mostly tabs I think)
5) Cut & Paste has mixed and strange results
6) the "Preview" window gets pushed way down on my screen and I can't scroll to see it or close it
6a) This also happens on the search page

Maybe I am just missing something? If it works fine for you in Chrome then something on my side must be funky. Chrome Version 31.0.1650.63 m
Hi both,

Hope you don't mind me re-hijacking the thread.

Wayne: Thanks so much for your suggestion. It works really well for cases where there are exactly 2 lines joined by a single "\n" newline sequence. The problem is that some addresses will contain one line and other may contain three lines. In both cases, it is sometimes necessary to return a BLANK depending on the number of "\n"s.

It seems to me that I need 3 dictionaries:

Address Line 1
Replacement Value: $1
Match On:
(.+)\\n(.+)

Match On:
(.+)\\n(.+)\\n(.+)


Address Line 2
Replacement Value: $2
Match On:
(.+)\\n(.+)

Match On:
(.+)\\n(.+)\\n(.+)

Replacement Value:-BLANK-
Match On: some regex

Address Line 3
Replacement Value: $3
Match On:
(.+)\\n(.+)\\n(.+)

Replacement Value:-BLANK-
Match On: some regex
Match On: some other regex

With regards to "some regex" and "some other regex", I've looked at both your earlier forum post and this stackoverflow question, but neither an approach based on
/^((?!\\n).)*$/s
nor
\b(?(\b\\n\b)MATCHED|.*)\b
seem to work.

Any tips?
This is way more fun than my real job!

Here is the correct expression. It's a bit crazy but it gets the job done!

(.+?)(?:\\n|$)(.*?)(?:\\n|$)(.*?)(?:\\n|$).*

You can use that in the three address line dictionaries and just change the replacement value to $1, $2, $3

It takes care of the blank-if-doesn't-exist scenario as well.

I won't go into the whole explanation but here are some hints
+? and *? = "lazy" matching meaning that it stops at the first match
(?:group) = non-numbered group. It matches but doesn't create a group to reference.
$ = end of line

The blank is created because * matched 0 or more so, in this case, it is matching 0 and therefore returning and empty string.
Wayne that's incredible. I had written some VB in the meantime, but this is much more elegant as it means I don't have to hard-code column names.

If you're ever in the UK, I owe you a beer.
Excellent!
Login or Signup to post a comment