#trying to create a regex to completely remove ALL instances of \r or \n at the end of a line

31 messages · Page 1 of 1 (latest)

willow vessel

just as the title says... rn i have /(\r|\n)+$/ but with this one my string goes from this:
" \r\n\r\nPlayable.\r\n- All graphic issues have been fixed.\r\n\r\n\r\n\r\n\r\n\r\n"
to this:
" \r\n\r\nPlayable.\r\n- All graphic issues have been fixed.\r\n\r\n"
any advice appreciated...im still not the best at regex

clever creek

make it global and multiline.

global allows the regex to match multiple times (normally it will only match once)
multiline allows ^ and $ to match the beginnings and ends of lines (normally ^ and $ are the beginning and end of the entire input string)

tbf, $ isn't actually needed at all since with m it's just defined as being after \n

you'll only ever realistically encounter \n or \r\n, \r is really outdated, so you could just use /\r?\n/g

willow vessel
clever creek

i see

i'll have to get back to you, gotta go do something rq

if i don't come back in like, 10 minutes ping me because i'd probably have forgotten it

willow vessel

cool thx

willow vessel

@clever creek

clever creek

yep i forgot just as predicted

aight here we go

your regex seems correct with that, i can't replicate the issue either

what code are you using?

also make sure to save and restart

willow vessel

im using latestComment.body.replace(/(\r|\n)+$/, "")

but there are always some \r\n left over

clever creek

show more code than that

how are you seeing that some are left over

willow vessel

output

the \r\n are still there 😦

i just want to make it so it ends like All graphic issues have been fixed....

URL finder is just a regex that matches URL's

clever creek

could you move your logs to right under finalCommentBody

to isolate 1 issue at a time, in case there's multiple

willow vessel

ok

i have to do something rn ill be back

plucky pier

Could it be that you remove all from the end but then cut off more because of the substring so those that are there in the end were in the middle originally?

willow vessel

i think its exactly that woah