Regular expression - starting and ending with a character string

后端 未结 3 425
梦如初夏
梦如初夏 2020-11-27 03:03

I would like to write a regular expression that starts with the string \"wp\" and ends with the string \"php\" to locate a file in a directory. How do I do it?

Examp

3条回答
  •  春和景丽
    2020-11-27 03:51

    ^wp.*\.php$ Should do the trick.

    The .* means "any character, repeated 0 or more times". The next . is escaped because it's a special character, and you want a literal period (".php"). Don't forget that if you're typing this in as a literal string in something like C#, Java, etc., you need to escape the backslash because it's a special character in many literal strings.

提交回复
热议问题