Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

regex - Regular Expression only match if String ends with target

I need a regular expression that will only match to the String if it ends with the target that I am looking for. I need to locate a file with a specific extension, problem is this extension also comes in other files. For example I have two files named

B82177_2014-07-08T141507758Z.ccf

and

B82177_2014-07-08T141507758Z.ccf.done

I only want to grab the first of these and my pattern is:

.*.ccf

but this grabs both.

Any suggestions appreciated, I am a newbie to regular expressions.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use an end anchor ($):

.*.ccf$

This will match any string that ends with .ccf, or in multi-line mode, any line that ends with .ccf.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...