Reputation: 364
I want to find any kind of uuid or random generated text in a url path and replace it with <random>
. Examples :
/test/ajs1d5haFkajs1dhasdd2as345sdAS3+Ddas9
= /test/<random>
/test/akKd9Ja3/ajs1d5haFkajs1ddasd623ha5sdAS3Ddas9=/30
= /test/<random>/<random>/30
/test/akKd9Ja3/Example-ASDAdddasd-108174.js
= /test/<random>/Example-108174.js
. /test/akKd9Ja3-ASj83asj-dask92qwe_ke
= /test/<random>
I'm looking for a solution that will match on a string:
/
AND/
or $
[0-9]
AND[a-z]
OR [A-Z]
-
, =
, _
, +
, \s
(spa.<something>
{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
.
Upvotes: 0
Views: 660
Reputation: 37755
Update - In case you want match must contain at least one digit.You can use this.
(?<=\/)(?=[\w-+=\s]+[0-9])[\w-+=\s]{7,}(?![.])(?!\.)(?=\/|\n)
You can try this.
(?<=\/)[\w-+=\s]{7,}(?!\.)(?=\/|\n)
Explanation
(?<=\/)
- Positive look behind. Matches '/'.[\w-+=\s]{7,}
- Matches any word character, -
,+
,=
, and space 7 or more time.(?!\.)
- Negative look ahead. Do not match .
.(?=\/|\n)
- Positive look ahead. Matches '/' or '\n'(New line).Upvotes: 1