|
#1
|
|||
|
|||
|
I am formatting output in HTML for a PDF Writer destination. The section headers in the OBX segments are always all caps and end with a colon (e.g. RECOMMENDATIONS: or FINDINGS
. I wrote a little code template that would evaluate the line and if it met the criteria of a section header it wraps the text in <b> and </b> and replaces the original text with the new bold formatted text. It worked well until I found that it only replaces the first instance. So if I have FINDINGS: and then later MORE FINDINGS:, only the first FINDINGS: is replaced. I tried regular expressions, but after several attempts at adding what I thought were the proper slashes and a /g it would not work at all, in that now nothing was being replaced. This was my original line of code. The var OrigText will contain 'FINDINGS:' and 'BoldText' will contain '<b>FINDINGS:</b>' PDFOut = PDFOut.toString().replace(OrigText, BoldText); I changed it to this in an attempt to get a global replace, but now I have a new problem. PDFOut = java.lang.String(PDFOut).replaceAll(OrigText, BoldText); This morning I came in and the javascript had throw a number of exceptions on the new line of code. One of the header sections had only an open parenthesis in it and java.lang.string did not like this. The original toString().replace() has no problem with this, but of course, it won't do a replaceAll(). So I'm stumped and I have spent too much time trying to do a global replace in a string with javascript. Can anyone help with this. The exception on java.lang.string is: Wrapped java.util.regex.PatternSyntaxException: Unclosed group near index 26 Cancer Society (web search Greg |
|
#2
|
|||
|
|||
|
I've done many global replacements in Mirth. Could you post some example code? Not just the call to the function, but the regex definitions as well. It looks like your regex isn't properly formatted based on the error description. Unclosed group means you probably have non-matching parenthesis inside the regex.
|
|
#3
|
|||
|
|||
|
Thanks for the reply. I'll look in to this more. There may be something else.
Last edited by GregD; 01-03-2012 at 09:51 AM. |
|
#4
|
|||
|
|||
|
String replace in javascript has stymied me on a number of occasions.
When all else fails this is my go to: Code:
var strOriginal = new String("Original String");
var strNew = new String("New String");
var pattern = RegExp(strOriginal,'g'); //you can add ,'i' after the global flag if you want case insensitive
var PDFOut = strOriginal.replace(pattern,strNew);
/* WARNING: I've spent the holidays working in arcane languages like CSS and HTML
and did you know they have this thing called Television that you can watch for hours and let your brain go to mush?
What I'm saying is that my syntax may be off. I'm playing catch up and don't have time to run code to test it
*/
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com http://www.linkedin.com/pub/david-rothbauer/5/923/518 hl7coders.wordpress.com Test all my code suggestions prior to implementation |
|
#5
|
|||
|
|||
|
Thanks for the reply. I still don't know why that one message barfs on the java.lang.String(PDFOut).replaceAll(OrigText, BoldText). I thought it was the open bracket, but could not reproduce it with other similar examples.
|
|
#6
|
|||
|
|||
|
Have you tried looking at it in a hex editor? Maybe there's an un-printable character in there somewhere.
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com http://www.linkedin.com/pub/david-rothbauer/5/923/518 hl7coders.wordpress.com Test all my code suggestions prior to implementation |
|
#7
|
|||
|
|||
|
Actually, I have moved on and lost track of the message. It was just a fluke that one of the few messages I was testing caused that problem. At the time, when trying to figure out what was going on, I took out the one '(' and received no exception. Put it back and it threw the exception.
After posted I tried to duplicate the problem with a simple string containing a '(' and couldn't. I have no idea what was causing it, but it hasn't happened since. Thanks, Greg |
![]() |
| Thread Tools | |
| Display Modes | |
|
|