Reputation: 9
Can you help me with the regex for deleting everything at the end of a string, if the end of the string start with ?_t_id=
ie:
domain.it/antioxidanter/?_t_id=187
domain.it/animaliska/?_t_id=211
Upvotes: 0
Views: 37
Reputation: 1523
To match the part you want to remove (replace by empty string), use
/\/\?_t_id=(?!.*\/).*/
This will match (bold):
To match the part you want to keep, to (re-)assign it to a variable, use
/(.+(?=\?_t_id=.*))|.+(?!\?_t_id=.*)/
This will match (bold):
Upvotes: 0
Reputation: 174696
Search:
\?_t_id=\d+$
replace with:
empty string
Since ?
is a special character, you need to escape that in-order to match a literal ?
symbol. In js,
string.replace(/\?_t_id=\d+$/m, '');
Upvotes: 1