开发者

How to say "Any Character" in regular expression?

开发者 https://www.devze.com 2023-01-25 11:13 出处:网络
I want to search for a line which starts with lets say a and ends with z. In-between any number of any character开发者_高级运维 can come. How can i write an expression for this?

I want to search for a line which starts with lets say a and ends with z. In-between any number of any character开发者_高级运维 can come. How can i write an expression for this? ( I dont want to explicity mention any digits, any special chars, any alphabets ) I don't to do something like ^[0-9,a-z,A-Z,list all special chars]*$.


How about:

^a.*z$

. is the regex metacharacter that matches anything.

* is a greedy modifier that repeats the previous item 0 or more times, trying for the biggest number of matches first, followed by smaller permutations until the preceding item cannot be matched at all, which will in fact, still make the overall regex match.


^a.*z$

If you want to change it from "any number (including zero) of characters" to "one or more characters", then change the * to +.

0

精彩评论

暂无评论...
验证码 换一张
取 消