04. Anchors begins and ends with

In some cases, you'll need to specify that a string starts and/or ends with certain characters. For example, if you were reading from an ouput, and had to match if it reads "success", you couldn't just write a regex that matches "success", as "not success" and "success did not occur" would also be valid matches.

Begins and Ends with

To specify that a string should strictly start or end with certain character, we can use the hat (^) or dollar sign ($).

^zip
Match all strings that start with zip.
zip$
Match all strings that end with zip.
^z..i.p$
Match all strings that start with z, has any two characters then an i, then another character, and ends with p.

Ace your Technical Interview

Elements of Programming Interviews

Ace your Technical Interview Try Algorithms

Learn all the different scenarios of . This book is jam packed with code snippets written in C++ and Java to give you the edge you need to ace your technical interviews. Problems come with detailed solutions as well as a hint in case you get stuck, and organized by difficulty level with several variants to help you apply your knowledge more widely.

$ Check price
39.9539.95Amazon 4 logo(240+ reviews)

More Algorithms resources

Build modern and responsive webpages

High Performance Web Sites

Build modern and responsive webpages Try Front-end

Want your web site to display more quickly? This book presents 14 specific rules that will cut 25% to 50% off response time when users request a page. Author Steve Souders, in his job as Chief Performance Yahoo!, collected these best practices while optimizing some of the most-visited pages on the Web.

$ Check price
29.9929.99Amazon 4.5 logo(63+ reviews)

More Front-end resources

Ad