I have a collection of url's and i need to write regular expression to filter needed content.
/data/43492-someText/"
/data/221639-anotherText/"
/data/116345-differentText/"
/data/6630-boooring/"
/data/220742-foo/"
What i need is only strings without /" on the end, so
/data/220742-foo
My Regular Expression looks like this:
@"/data/[0-9]{1,10}-.*""\s"
Note: I dont want to do this with string replace, because of some limitations on my project.
If that (string not ending in /
) is the only requirement, then use something like this:
var desiredUrls = urls.Where(url => !url.EndsWith("/\""))
I initially read the question as a desire to filter urls but I can see how it could be a mapping question.
var withoutSuffix = urls.Select(url => url.TrimEnd("/\"".ToCharArray());
I think Regular Expressions are kind of overkill for what you're trying to do.
Anyways you can use something like this :
@"/data/[0-9]{1,10}-[^/]+"
您可以使用TrimEnd
从字符串末尾删除字符:
s.TrimEnd('/', '"')
You could use something like:
(/data/[0-9]{1,10}-.+)/
And the string without the trailing / will be in the first capture group.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.