I want to match the nth hyphen in the regular expression.
For example, I would like to know the regular expression that matches and removes the right -fdfd-fd
from the second hyphen from the left in the URL below.
If you want to match it from the first time, it's -.*
.
https://www.example.com/a-12345-fdfd-fd
regular-expression
This is an example of a regular expression to match for the second time
^[^-]*-[^-]*-
You can delete it from the second time to the right with perl
s/^([^-]*-[^-]*)-.+$/\1/
© 2024 OneMinuteCode. All rights reserved.