Help: delete everything except (letters and numbers) only

A swapping-ground for Regular Expression syntax

Help: delete everything except (letters and numbers) only

Postby xrescom » Sat Apr 18, 2020 8:43 pm

hello everyone

As is evident in the question

i need delete everything except letters (english+arabic) and numbers and only this char ( _ - + () )

Example :
From
Code: Select all
0001 avenger _ #Last-Movie = ( *& ^^^ ???????????? )@@+$exstra.mp4

to
Code: Select all
0001 avenger _ Last-Movie ( ????????? )+exstra.mp4
xrescom
 
Posts: 2
Joined: Sat Apr 18, 2020 8:29 pm

Re: Help: delete everything except (letters and numbers) only

Postby RegexNinja » Sun Apr 19, 2020 12:56 am

Insofar as I know, BRU's regex cant match unicodes, including arabic like: [\u0600-\u06ff].
Just for fun, I did try the \x06[\x00-\xff] 'equivalents', but had no success in matching them.

As ironic as it sounds, you can reverse-match against them with [\x00-\xff].
So for the example given (no arabics), you could use:

#12Filters:
Mask=^[\x00-\xff]*$
RegEx=Checked
F5/Refresh to apply the filter

#5Remove:
D/S=Checked

#1Regex Match/Replace:
(?i)([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*([- _+()?a-z0-9]*)[^- _+()?a-z0-9]*(.*)
\1\2\3\4\5\6\7\8\9

Regex Notes:
The regex is just ([- _+()?a-z0-9]*)[^- _+()?a-z0-9]* repeated 7-times, with a final (.*) to match everything-else.
So it removes a max of 8 'special-character-strings' in filename, preseving only: Digits, Alphas, and: ?_-+()
It cant touch filenames with arabics, because #12's mask filters them away.

Results:
0001 avenger _ #Last-Movie = ( & ^^^ ??? )@@+$exstra ----> 0001 avenger _ Last-Movie ( ??? )+exstra
Begin_Text #[]{};$,=@ Middle-Text ^]{~%!, (End-Text) ------> Begin_Text Middle-Text (End-Text)

Cheers
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Delete all chars not in my approved-set

Postby RegexNinja » Tue Apr 21, 2020 3:14 am

BRU's javascript does support \u for Unicodes.
So depending on which Arabics you wanna keep, you could use something like:

Special/JavascriptRenaming:
newName=name.replace(/ *[^- _+()?a-z0-9\u0600-\u06ff]/ig, '')

This one also removes space before any of the undesired-chars to achieve results like:

001Avenger _ #Last-Movie = ( & ^ # Text )@@+$extra ---> 001Avenger _Last-Movie ( Text )+extra
Begin_Text #[]{};$,=@ Middle-Text ^~%!, (End-Text) -----> Begin_Text Middle-Text (End-Text)
?e?in-text_?#~ Middle-Text ^~;$[]{},=@%!,(End-Text) ---> ?e?in-text_? Middle-Text(End-Text)
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Help: delete everything except (letters and numbers) only

Postby RegexNinja » Tue Apr 21, 2020 3:21 am

Note: All of the ?'s in the last example represent an Arabic character.
This forum doesnt like them very much, for some reason.
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm

Re: Help: delete everything except (letters and numbers) only

Postby xrescom » Wed Apr 29, 2020 4:21 pm

Thank you all for the responses
I got an idea and I'll try it now

I apologize very much for the late reply
We have big problems with the internet :cry: ... I repeat my apologies again
xrescom
 
Posts: 2
Joined: Sat Apr 18, 2020 8:29 pm


Return to Regular Expressions