Removing a last character in a variable.


Badge +8

Hi all, I have what I hope is a fairly easy question. I'm using some regex to manipulate some data in a multiline text box. It removes some characters, puts them all in a new line and adds brackets to the left of them. And example below:

[  ] Microsoft Word

[  ]Firefox

[  ]Internet Explorer

[  ]

My problem is with that last bracket as it places that at the end. So far any pattern I used gets rid of all of the brackets. Is there a way to just trim that last one so it can look like this:

[  ] Microsoft Word

[  ]Firefox

[  ]Internet Explorer

Thank you in advance.


9 replies

Userlevel 5
Badge +14

could you provide some sample of your source data? (ideally if you could attach a text file so that it doesn't get (mis)interpreted by a browser

it looks like you have an empty trailing in input and you just prepend it with braces...

Badge +8

Of course here you go. Basically I have a form that's pulling from an XML file I created. The text comes as attached as you can it adds the ;# that seems to be a bug that SharePoint has when pulling some data. It also comes wrapped. So basically I use regex to check for that patter and replace with {Common:NewLine};[  ]

Thanks again

Badge +8

Of course here you go. Basically I have a form that's pulling from an XML file I created. The text comes as attached as you can it adds the ;# that seems to be a bug that SharePoint has when pulling some data. It also comes wrapped. So basically I use regex to check for that patter and replace with {Common:NewLine};[  ]

Thanks again

Userlevel 5
Badge +14

something like this might work

regex pattern

(^;#|)(?<text>.*?)(?=|)(|.*?;#)

replacement

(note the extra line feed. based on usage of the output you might need to replace it with a ' ' or NewLine reference)

[ ]${text}

214273_pastedImage_2.png

Badge +8

Thank you so much Marian that worked. Just one last thing there's another list of software. Also with ;# in front although there's no piping in any of the names so I think that's why your pattern isn't working. I changed it a bit so it does add a bracket but only one as you can see below. I'm sure it's something simple I'm missing. 

(^;#)(?<text>.*?)(?=;#)(.*?;#)

Userlevel 5
Badge +14

try following

(;#)(?<text>.*?)(?=;#|$)

214292_pastedImage_1.png

Badge +8

Thank you Marian I used it and it worked but I noticed there was still a character at the end. I double checked and it looks like that software actually before any regex happens comes out ;#Firefox;#Tableau Reader;# not ;#Firefox;#Tableau Reader as I originally thought. So it looks like there's a extra ;# at the end of the software list. 

I apologize for not noticing that before. If we can get this last part this will be it. Many many thanks.

Userlevel 5
Badge +14

should be easy from above, shouldn't it? laugh.png

(^;#|)(?<text>.*?)(;#)
Badge +8

Yes it was I've got it all working now. Thank you SO much for your help Marian. Many thanks.

Reply