Home > Mobile >  How to find regex for multiple conditions
How to find regex for multiple conditions

Time:01-31

I am trying to find regex which would find below matches. I would replace these with blank. I am able to create regex for few of these conditions individually, but I am not able to figure out how to create one regex for all of these

Strings:

song1 artist  (SiteWithMp3Keyword.com).mp3
02.song2 | siteWithdownloadKeyword.in 320 Kbps
  song3 [SitewithDjKeyword.in] 128kbps.mp3 

Output

song1 artist.mp3
song2
song3.mp3

Criteria for match:

  1. Case Insensitive
  2. Find Strings with particular keyword and remove whole word, even if inside any braces
  3. Find kpbs keyword and remove it along with any number before it (128/320)
  4. if string ends in .mp3, keep it as it is.
  5. Remove junk characters (like | ) and replace _ with space.
  6. Remove number if present at start of string, like 001_ 02. etc.
  7. Trim whitespaces before and after remaining string

Example Regex for 2.

\S (mp3|dj|download)\S 

enter image description here

  •  Tags:  
  • Related