rpaterick Posted June 28, 2010 Share Posted June 28, 2010 adding dashes after every 4th character. This didn't work for data below. return Str(Field("MY_BARCODE").replace(/(\d{4})(?!$)/g,"$&-"));SAMPLE DATA: AXURDNNWUN2YN59H BGV9RFT3WQAD3K7J 6JYDM2CYXCKAZQJ6 KYEW4ZS6G9F4A449 UK2QWYPE5SVT58LY R84QSLF8TT5C6YFM ZT4PR8RGDVE6QLHU 93BDX97RTY467GY9 QTM6KGMVVN64VP7G WLZTPR7SFLGCKTX6 Link to comment Share on other sites More sharing options...
rpaterick Posted June 28, 2010 Author Share Posted June 28, 2010 I got it to work a different route. str = Field("code").substr(0,4) + "-" + Field("code").substr(4,4) + "-" + Field("code").substr(8,4) + "-" + Field("code").substr(12,4); return str; Link to comment Share on other sites More sharing options...
Dan Korn Posted June 28, 2010 Share Posted June 28, 2010 adding dashes after every 4th character. This didn't work for data below. return Str(Field("MY_BARCODE").replace(/(\d{4})(?!$)/g,"$&-"));SAMPLE DATA: AXURDNNWUN2YN59H BGV9RFT3WQAD3K7J 6JYDM2CYXCKAZQJ6 KYEW4ZS6G9F4A449 UK2QWYPE5SVT58LY R84QSLF8TT5C6YFM ZT4PR8RGDVE6QLHU 93BDX97RTY467GY9 QTM6KGMVVN64VP7G WLZTPR7SFLGCKTX6 The problem is the \d in your regular expression. That matches only digit characters (0-9), not all alphanumeric characters as in your sample data. Try \w (any alphanumeric character) instead: return Field("MY_BARCODE").replace(/(\w{4})(?!$)/g,"$&-");Note that the "Str" function wrapping everything is superfluous, so I removed it. Also, if you want to avoid a trailing dash at the end, instead of using ?!$ to say, "not at the end of the string," just use String.match and String.join instead, like so: return Field("MY_BARCODE").match(/(\w{4})/g).join("-"); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.