Why cant u just use gr instead of ^gr | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why cant u just use gr instead of ^gr

In regular expression characters

22nd Sep 2018, 1:36 PM
Amasa Abubakar
Amasa Abubakar - avatar
2 Answers
+ 2
<p> Kevin</p>, in your example there won't be a match because ^amasa$ means that the whole string has to be amasa and there can't be anything before (^) or after ($) that. ^ and $ refer to the whole string, not to the regex pattern. You could match the string ImamasaHere with a pattern like ^Im(.*?)re$ . gr will match a string if gr is anywhere in the string: "great" <= match "not great" <= match ^gr means that the string has to begin with gr: "great" <= match "not great" <= no match
22nd Sep 2018, 6:01 PM
Anna
Anna - avatar
+ 1
^ symbol, indicate that start. and $ as the end. lets say i have a pattern "amasa", with string " ImamasaHere". the result will be the same using search. i want only "amasa"... so... the pattern is " ^amasa
quot;. i hope its help
22nd Sep 2018, 3:20 PM
Kevin AS
Kevin AS - avatar