I tried to search this question first but didn't found what I need, here is it:
I have a string like: "substring1/substring2.substring3" (eg "library/History.read")
I need a regular expression to check:
I'm not familiar with regular expression, the current I wrote is: 'library/([a-zA-Z])\\.(read)'
but it is not correct. Please help me, thanks!
There are many ways to solve regex problems, starting from your own attempt here's something that works: :-)
library/([A-Z][a-zA-Z]+)\.(read)
You had three small mistakes:
.
is a character class matching any character except newline. Escape your .
like this \.
not like this \\.
; and+
qunatifier to match one or more.Try this regex:
testStrings = ["library/History.read", "library/other.read", "library/Geography.read", "library/History.unread", "ebook/hstory.read", "library/StackOverflow.read"] regex = /library\/[AZ][^\.]*\.read/ testStrings.forEach(testString => { console.log(regex.test(testString) + " - " + testString) })
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.