ghDaYuYu / foo_discogger

Discogger
57 stars 0 forks source link

Question - Reg exp engine #75

Closed stephen147 closed 2 years ago

stephen147 commented 2 years ago

What reg exp engine does this use?

The regex to trim, just an example doesn't work as it should.

(^ +| +$)

It replaces all white spaces.

It appears the ^ or the $ don't work.

I was trying to remove any unwanted whitespace from RELEASE_NOTES

1st regexp is to trim end of each line. 2nd is to remove extra blank lines. 3rd is to replace two whitespaces with one.

This appears to work

$trim($multi_replace_exp($multi_replace_exp($multi_replace_exp(%RELEASE_NOTES%,' +(?=\r?\n)',),(\r?\n\r?\n)\r?\n+,$1), +, ))
ghuDaYuYu commented 2 years ago

Regexp is imported from c++ standard library.

It appears that expressions are failing due to a bug in the component, causing invalid (duplicated) backslash escape sequences. The following expressions may help you understand whats going on and hopefully provide some assistance until it's fixed,

left trim: $multi_replace_exp(' lt lt lt ','^\s+',)

right trim: $multi_replace_exp(' rt rt rt ','\s+$',)

stephen147 commented 2 years ago

Thanks for that mate!

I'm trying to test with newlines as the input string. Is there any way to do this?

I've tried:

$multi_replace_exp(' rt rt rt $crlf() aa','(^ +| +$)',)

and

$multi_replace_exp(' rt rt rt \n aa','(^ +| +$)',)
ghuDaYuYu commented 2 years ago

You're welcome👍 fix for backlashes in regex definitions should be included in v1.08.

You may try testing with expression:

$multi_replace_exp(' aa '$crlf()$crlf()' bb ','(^ +| +$)',)

In my test, output seams correct:

aa

bb

Great sanitizing expression, thank you!

ghuDaYuYu commented 2 years ago

I am closing this issue with v.1.0.9.

The following tests for ^ and $ metacharacters and CR removal seam ok here. But feel free to reopen or create a new issue, if you like... 👍

LTRIM $multi_replace_exp( lt lt lt ,'^\s+',) RTRIM $multi_replace_exp( rt rt rt ,'\s+$',) RPL_CR $multi_replace_exp(%ARTISTS_PROFILE%,$crlf(),#) RPL_CR_AND_WHITESPACES $multi_replace_exp($multi_replace_exp(%ARTISTS_PROFILE%,$crlf(),#),'[ \t\r\n\f]+',#)

stephen147 commented 2 years ago

Thanks. I'll test this and get back to you if all goes Pete Tong 🤣

ghuDaYuYu commented 2 years ago

What? 🤣

stephen147 commented 2 years ago

What? 🤣

It's a famous expression.. lol.. https://www.phrases.org.uk/idioms/its-all-gone-pete-tong.html