jeudi 6 décembre 2018

Regex to finding any kind of uuid or random generated text

I want to find any kind of uuid or random generated text in a url path and replace it with <random>. Examples :

  1. /test/ajs1d5haFkajs1dhasdd2as345sdAS3+Ddas9 = /test/<random>
  2. /test/akKd9Ja3/ajs1d5haFkajs1ddasd623ha5sdAS3Ddas9=/30 = /test/<random>/<random>/30
  3. /test/akKd9Ja3/Example-ASDAdddasd-108174.js = /test/<random>/Example-108174.js.
  4. /test/akKd9Ja3-ASj83asj-dask92qwe_ke = /test/<random>

I'm looking for a solution that will match on a string:

  • starting with / AND
  • end with / or $
  • contain [0-9] AND
  • contain [a-z] OR [A-Z]
  • CAN contain -, =, _, +, \s (spa
  • DOES NOT contain an extension i.e .<something>
  • 7 char and longer {7,}

This is what I used so far : /[a-zA-Z0-9-=_+\s]{30,}

This works for most cases since uuids are often longer than 30 char. But I don't catch the small ones i.e /5c88148/ or /6qdkKdk5/. I also match on things like Example-ASDAddasd-108174.js.




Aucun commentaire:

Enregistrer un commentaire