You are viewing limited content. For full access, please sign in.

Question

Question

Using Regular Expression to parse out Address Field in Forms

asked on January 9, 2014

We're capturing the Address from the Forms into a Template field, however, the information gets stored in a single field in the Template and we'd like to be able to break it out so that instead of it looking like the following:

123 Main St, Lasertown, CA, 90210

 

We'd like it to put 123 Main St into Address 1

Lasertown into City

CA into State

90210 into Zip.

 

I'm having an tough time coming up with the Regular Expression to use in Workflow to parse out the single line Field?  Any help would be appreciated.

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on January 9, 2014 Show version history

You are using Forms or Workflow to save the template information? It is slightly ambiguous in your question where the regular expression is being used.

 

I think you mean Workflow. In that case, you should try parsing it at every comma(using a function (split)), making it a multi-value token. Then use the values in the following positions to assign the fields:

 

you should test for how many values are in the token, to see if you have a second address row in there, or you can do the following to get only the first address row:

  • Position 1 from the start is the Address 1
  • Position 1 from the end is the Zip Code
  • Position 2 from the end is the State
  • Position 3 from the end is the City

 

To Split the token, do this: 

 

If there are 5 values in the token, and you had an Address 2 field to retrieve, then the above setup would still always work, but you would also want to have it take the value in the 2nd position from the start and assign that to your Address 2 field.

 

To Find out the amount of values for use in a conditional decision, do this:

1 0
replied on January 17, 2014

Kenneth, 

This is now working...however, in forms....there is a possibility that they can "Add" more addresses...so our template fields are mutli-field values...so I'm not sure how to use the above solution to accomodate the multi-field value?

0 0

Replies

replied on January 9, 2014

So the comma is the delimiter? Would they ever have more than 4 pieces of info in there (like an apartment number)?

 

([^,]+) set to "all matches as a multi-value token" should do it. You can use indexing on the multi-value token to get the first value into Address1. You could also use indexing, but counting from the end to get the City, State and Zip in case there is more to the address than just the street, city, state and zip.

0 0
replied on January 9, 2014 Show version history

Yes, it is possible that they put a PO Box or Apt. # in address 2.  I have to say I'm not real versed in regular expressions.  I'm not completely following the above directions.  Where I'm at is in the Workflow Token Dialog...I've checked Regular Expression and have figured out how to get the first line in the comma delimited field...what I can't figure out is how to get the 2nd, 3rd, and 4th, (and possibly 5th).

 

So Test, Test2, Test3, Test4, Test5....I'm able to parse out Test an put that into a field...but I can't figure out how to get the remaining Test2 Test3 Test4 and Test5 into their respected fields.

0 0
replied on January 9, 2014

you set the index, just try it out in the token editor just like in my screenshots and you should get a better understanding. 

 

Is there a reason to do it with regular expression? 

0 0
replied on January 9, 2014

Oh, I see, you're trying to do it with in-line pattern matching. You could do it like that, but the regular expression would get ugly fast because in this case you actually have to specify the groups. So it would be something like %(Token #<^([^,]+)>#) for the first group, %(Token#<([^,]+)$>#) for the last, %(Token#<([^,]+),[^,]+$>#) for the next to last and so on.

 

It's easier if you add a Pattern Matching activity that converts the single-value token into a multi-value token using the syntax above (btw, that regular expression is just saying "everything except commas" - [^EXCLUDED_CHARS_GO_HERE]).

 

Then in the Token Dialog, use the "Apply Index" section rather than the Apply Regular Expression one. Index 1 from the end will give you "Test 5", index 2 from the end will give you "Test 4" and so on.

 

Kenneth makes a good point above about using the Split function since this is a pretty straightforward case. If you use the function, you don't need the Pattern Matching activity, you can just use the Split function and indexing right on the original value.

0 0
replied on January 9, 2014

Have you considered that the respondent may not use commas?

If you are using the Laserfiche Forms engine, why not drag out an "address" field type? It splits all of the different inputs in to different tokens that you can then use and feed in to a single Laserfiche field, if that's how you want it in Laserfiche.

replied on January 9, 2014

Let me clarify myself...we are using the Address Field type in Forms (Address1, Address2, City, State, Zip, Country).  However, when we try to map the fields to a Template...all the Address information gets put into a single Template Field...separated by commas.  We want the information into separate Fields for future needs.  Kenneth...to answer your question...is there another way to do this without using Regular Expressions?  I'm open to suggestions.

0 0
replied on January 9, 2014

Look at my initial response, you can simply do what i recommend and then check "Apply Index" and apply those position numbers like i say. To start the index from the end, simply click on the "start" that looks like a hyperlink and it will change to end.

0 0
replied on January 9, 2014

Kenneth, OK...I followed what you recommended...thank you for that.  Now the question that I have and perhaps I'm just not seeing it...is now that I've got the Expression created properly...how do I map it to the proper field?  So let me try to explain.  I'm "Routing an Entry" and in the Route the Entry...I'm choosing to assign fields...and that's where I'm using the Token Editor.  Now I have a Field called "Address" which is where Forms dumps the single line address (123 Main St, Lasertown, CA, 90210).  But I want to map the 123 Main St to the (Address 1 Field), Lasertown to the (City Field), CA to the (State Field) and so on.  I'm not seeing how I do that as I created the Expression...but how do I ensure that each field get's populated with the proper item?

0 0
replied on January 9, 2014

The Split function will take "123 Main St, Lasertown,CA,90210" and convert it into a multi-value token with the following values:

  • 123 Main St
  • Lasertown
  • CA
  • 90210

You can use indexing to specify which value goes where. The only trick is that for the city, state and zip code, you'd have to specify the values counting from the bottom up since you can't tell for sure if you have 4 or 5 values (yes, you can count them, but that's sort of a waste of time since you really don't care if there are 4 or 5. You just want the first one in the Address field and the last 3 in City, State, Zip, respectively)

 

 

0 0
replied on January 10, 2014

Miruna,

Thanks for the info.  I'm able to get the parsing out...however, it's not actually mapping the broken out info into the proper fields...it's all staying in the original field?  I've attached screenshots of my setup.

 

Thanks!

Template.PNG
Field settings.PNG
Template.PNG (51.53 KB)
0 0
replied on January 10, 2014

Have you checked the instance details? Are there any errors/warnings?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.