I am a little bit confused about the ^
symbol in regex.
From what I read online it means : "Finds regex that must match at the beginning of the line."
I read about the example presented here : https://regexone.com/lesson/line_beginning_end
" In the example above, we can use the pattern ^success
to match only a line that begins with the word "success", but not the line Error: unsuccessful operation
My confusion comes from the fact that ^success
will only match with the string "success" right ? So what is the point of ^
In the examples below ? I would have expect the second to also be true, based on the description of the ^
symbol.
System.out.println(Pattern.matches("^success","success")); // true
System.out.println(Pattern.matches("^success","success is good")); // false
Can anyone give me any clear examples with this ^
symbol used in regex?