How to replace value only if it occurs at the start of the field

Following on from my earlier question I’ve been experimenting with the post-function functionality. I’m extracting a block of text but want to remove blank lines. Phil provided a snippet of JavaScript to replace multiple “<br /&gt;” with a single one.

What I’m trying to do now is remove ANY that occur at the start of the string. The text extracted is “<br />The Owner<br />of a prop<br /><br />”.

The caret is the normal method of anchoring the comparison to the beginning of the string but I can’t get it to work. My post-function reads replace(/^<br /&gt;/,“”); If I remove the caret it removes the 1st occurrence so I’m thinking I must have an error in my caret.

Any pointers?

Thanks

Doug

Try:

replace(/^&lt;br \/&gt;/,"")

You only need to “escape” (i.e. with the \ ) the “/” character inside the BR token.

Hi Doug,

You can try this RegExp, which should work with your text extracted.

.replace(//gi, " ");

This code will replace all on your extraction and replace it for a white space.

You can check an example with your extraction clicking on this link https://jsfiddle.net/jcwdeveloper/54y1s6ke/

Please let me know if it’s works for you.

Best Regards,

Juan

Thanks Juan,

Odd isn’t it. For days now I’d been struggling with this. Come in this morning, type in a regexp and it worked! I’d ended up with replace(/(\s+)|(){2}/g,“”).replace(/^/,“”);

The first replace gets rid of white spare and double and the second replace removes any from the start. Might not be pretty but it works!

Thanks

Doug